2009-07-23 6 views
11

내 HTML은 다음과 같습니다작은 따옴표를 JQuery 속성 같음 선택자 ([attribute = value])에 넣을 수 있습니까?

 <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'); 
}); 

내가 거기에 작은 따옴표와 함께 일할 수있는 선택을 얻을 수 있습니다. "\"백 슬래시로 따옴표를 이스케이프하려고했지만 그게 도움이되지 않았습니다.

제안 된 방법에 대한 아이디어가 있습니까?

답변

13

난 당신이 이상하게 이중 백 슬래시를 필요가 있다고 생각이

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

+1

감사합니다. b/f를 게시하려고 시도 했어야합니다 ... – orandov

3

을보십시오. jQuery가 어떻게 이러한 문자열을 이스케이프 처리하는지에 관한 것. 따라서 당신은 다음과 같이 나타낼 수 있습니다 :

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

다른 상황에서도 마찬가지입니다. 이 시간에 작동하는지 알려주세요. 이들의

5

없음 IE에서 나를 위해 일한, 그래서 나는 필터()를 사용했다 :

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