How to select a div in jquery using id. That id which is store in variable.
<div id="d3">
some thing is here...
</div>
jquery Code:
var id = 3;
$("#d" + id)
I am using this code but this is not working.
How to select a div in jquery using id. That id which is store in variable.
<div id="d3">
some thing is here...
</div>
jquery Code:
var id = 3;
$("#d" + id)
I am using this code but this is not working.
This i working.
Example: Fiddle
HTML:
<div id="d3">
some thing is here...
</div>
Javascript:
var id = 3;
$("#d" + id).html("Change it!");
Your code is correct and getting the element by the selector check it here, you need to check following.
var id = 3;
alert($("#d" + id).html()); // shows some thing is here... in alert.
If you need to select a div here is the code,If i understand your correctly your want to select the text some thing is here...?
<div id="d3">
some thing is here...
</div>
$(function() {
var id = 3;
$("#d3" + id);
});