1

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 ??

1
  • 2
    document.getElementById("check" + a).innerHTML = "correct"; if using jquery: $("#check" + a).html("correct"); Commented Sep 28, 2013 at 8:53

3 Answers 3

2

JS:

document.getElementById("check" + a).innerHTML = "correct";

Jquery:

$("#check" + a).html("correct");
Sign up to request clarification or add additional context in comments.

Comments

1
$('#check' + a).html('correct');

or

$('#check' + a)[0].innerHTML = ('correct');

or

document.getElementById('check' + a).innerHTML = ('correct');

Comments

0

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');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.