开发者

Jquery defining id with a variable

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜