Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I put a single quote in a JQuery attribute equals selector ([attribute=value])?

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 on what is proffered way?

like image 473
orandov Avatar asked Jul 23 '09 21:07

orandov


2 Answers

Try two

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

like image 66
redsquare Avatar answered Oct 18 '22 21:10

redsquare


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');
like image 31
Captain Obvious Avatar answered Oct 18 '22 21:10

Captain Obvious