jnvnsn Posted November 8, 2011 Share Posted November 8, 2011 $(document).ready(function(){ //var cname = $(this).attr('class'); //var iname = $(this).attr('id'); $("li").click(function(){ var cname = $(this).attr('class'); var iname = $(this).attr('id'); var cname2 = "." + cname; alert(iname); $(".red").toggleClass("highlightyellow"); }); $("#rob .highlightyellow").click(function(){ $(".highlightyellow").toggleClass("red"); }); }); how can i pass cname to this line $(".red").toggleClass("highlightyellow"); ? Quote Link to comment https://forums.phpfreaks.com/topic/250667-pass-a-variable-to-a-selectorjquery/ Share on other sites More sharing options...
trq Posted November 8, 2011 Share Posted November 8, 2011 $("." + cname).toggleClass("highlightyellow"); Quote Link to comment https://forums.phpfreaks.com/topic/250667-pass-a-variable-to-a-selectorjquery/#findComment-1286089 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.