jQuery 1.5 click functions bug?

438 views Asked by At

Have same js code:

$("#pr_list .c").bind({
   click: function(event) {
       var m = $(this);
       var u = m.attr("rel");

       var lOpen = $("div.txt[rel="+u+"]");
       lOpen.html("!!!").slideDown();
   }
});

Have same html code

<div id="pr_list">
    <div class="w c" rel="1">same text</div>
    <div class="txt" rel="1" style="display: none;"></div>
    <div class="w c" rel="2">same text2</div>
    <div class="txt" rel="2" style="display: none;"></div>
</div>

When click on "same text" opens all div with class txt, not check same rel attr.. why?

Update: Ок, how about real example: http://jsfiddle.net/3nYXA

3

There are 3 answers

0
Sanghyun Lee On BEST ANSWER

Your code has problem in here.

var lOpen = $("div.txt[rel="+u+"]");

You should change this to:

var lOpen = $("div.txt[rel='"+u+"']");

Quotation marks were missed. It was fine at jQuery 1.4.x, but from jQuery 1.5 it doesn't work.

Check this out. http://api.jquery.com/category/selectors/attribute-selectors/

1
jAndy On

Works just fine: http://www.jsfiddle.net/JxEsK/

You got a typo in the selector for the .text.

3
Guillaume86 On

In your sample, the class names txt and text are mixed, this works:

http://jsfiddle.net/N9EDj/