views:

311

answers:

3

My Html looks like this:

        <a href="#" id="QuoteTest">Click Here</a>
        <ul>
            <li title="this" style="position:relative">one</li>
            <li title="this" style="position:relative">two</li>
            <li title="tha't" style="position:relative" >three</li>
            <li title="tha't" style="position:relative">four</li>
         </ul>

Jquery:

$('a#QuoteTest').click(function() {
    $('li[title=this]').animate({ 'left': '+=40px' }, 'slow');
    $("li[title=tha't]").animate({ 'top': '+=40px' }, 'slow');
});

I can't get the selector to work with a single quote in it. I tried escaping the quote with a, "\", backslash but that didn't help.

Any ideas?

Thanks.

+5  A: 

Try two

$("li[title=tha\\'t]").animate({ 'top': '+=40px' }, 'slow');

redsquare
Thanks. Should have tried that b/f I posted...
orandov
+2  A: 

I think you need a double backslash, oddly enough. Something about how jQuery escapes those strings. So you'd have:

$("li[title=tha\\'t]").animate({ 'top': '+=40px' }, 'slow');

That's been the case in other situations. Let me know if that works this time.

Gabriel Hurley
A: 

None of these worked for me in IE, so I had to use filter():

$("li").filter(function(index){
    return $(this).attr("title") == "tha\'t"; 
})
.animate({ 'top':'+=40px' }, 'slow');
Captain Obvious