using variables in rel attribute in jquery selector

有些话、适合烂在心里 提交于 2019-12-22 04:22:31

问题


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

回答1:


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();  


来源:https://stackoverflow.com/questions/1322198/using-variables-in-rel-attribute-in-jquery-selector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!