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"); ? 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"); 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
Archived
This topic is now archived and is closed to further replies.