how to add a # to a var
Hi h have some code which brin开发者_开发知识库gs back the class name of a link
var activeTab = $(this).attr("class");
so lets say the above brings back a value of 'one'
i need to append this to be #one for the below code
var activeTab = $(this).attr("class");
$(activeTab).stop(true, false).animate({ height: "200px" });
thanks in advance
Very simple in Javascript:
var_name = '#' + var_name;
You can use + for string concatenation:
$('#' + activeTab)
You can use + operator for string concatenation like this:
$('#' + activeTab)
var activeTab = $(this).attr("class");
activeTab = '#' + activeTab;
$(activeTab).stop(true, false).animate({ height: "200px" });
$('#' + activeTab) ....
?!
var activeTab = $(this).attr("class");
$("#" + activeTab).stop(true, false).animate({ height: "200px" });
var activeTab = "#" + $(this).attr("class");
$(activeTab).stop(true, false).animate({ height: "200px" });
I think that's what you want to do.
精彩评论