Warren Colbert
Warren Colbert

Reputation:

using variables in rel attribute in jquery selector

I'm using the rel attribute to match a div to a button. I use the button's id in the corresponding div's rel field. There are multiple buttons. When a button is clicked I want to show the corresponding div with the show() method, and to hide the other divs. The buttons work fine, but the divs are not responding. My gut says I'm not formatting the selector properly. Thanks.

    $("div.media_button").click(function (){

   var relid = this.id;

   $("div.media_button").not(this).fadeTo("normal",0.33);
   $(this).fadeTo("normal",1);
   $("div.media_selection[rel!='" + relid + "']").hide();
   $("div.media_selection[rel='" + relid + "']").show();   
 });

Upvotes: 9

Views: 35202

Answers (1)

redsquare
redsquare

Reputation: 78667

You do not need the single quotes. Can you paste the markup just incase the below doesnt end up working.

$("div.media_selection[rel=" + relid + "]").hide();
$("div.media_selection[rel=" + relid + "]").show();  

Upvotes: 15

Related Questions