Reputation: 59
HTML In my html I have an element with id ="check1"
<span id="check1"></span>
JAVASCRPIT I have a variable a='1', which is coming from somewhere else. Now, I want the inner HTML of span element to be "correct" with the help of reference to its id, and using 'a'.
var a = 1;
$.(#**checka**).innerHTML="correct"
How to write the id ??
Upvotes: 1
Views: 1856
Reputation: 4882
$('#check' + a).html('correct');
or
$('#check' + a)[0].innerHTML = ('correct');
or
document.getElementById('check' + a).innerHTML = ('correct');
Upvotes: 1
Reputation: 1340
first notice that innerHTML()
is javascript
and the jquery
function is html()
and always remember that you can use concatenation everywhere.
with that said:
$('#check' + a).html('correct');
Upvotes: 0
Reputation: 7447
JS:
document.getElementById("check" + a).innerHTML = "correct";
Jquery:
$("#check" + a).html("correct");
Upvotes: 2