开发者

Jquery defining id with a variable

开发者 https://www.devze.com 2023-04-12 06:50 出处:网络
So this works fine, as you all know $(\"#foo\").html = \"bar\"; But how would I do this? var i = 开发者_StackOverflow\"foo\";

So this works fine, as you all know

$("#foo").html = "bar";

But how would I do this?

var i = 开发者_StackOverflow"foo";
$(i).html= "bar";

I've tried $("#"+i) as well, but that doesn't work either.


This does not work.

$("#foo").html = "bar"; //Overwrites the object's html function with a string

This should.

$("#"+i).html("bar"); //Sets the inner HTML of the selected element.


i don't know what are you tring to do

but if you want to insert this value bar in the id='foo'

you can use

   var i = "foo" ;

   $('#'+i).html("bar");
0

精彩评论

暂无评论...
验证码 换一张
取 消