Jump to content

pass a variable to a selector(jQuery)


jnvnsn

Recommended Posts

   $(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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.