Reputation: 7683
I have in my
this.nameHtml
a DOM object with value:
<span class='test-name'>333</span>
I want to access the innerHTML i.e. 333
basically I am creating a checkbox element and want to assign the 333 value from DOM object in name attribute as follow:
checkBox = document.createElement("input");
checkBox.type = "checkbox";
checkBox.name = this.nameHtml; // Here i want to store 333
checkBox.className = "TriageCheckBox";
Please suggest a way.
Upvotes: 0
Views: 55
Reputation: 974
checkBox.name = this.nameHtml.innerText;
Beware of innerHtml! This may print unwanted html code and destroy your site structure! Difference between innerText and innerHTML in javascript
Regards, Benedikt
Upvotes: 0
Reputation: 512
Try using innerHTML
property :
checkBox.name = document.getElementByClassName("test-name")[0].innerHTML;
NB : document.getElementByClassName("test-name")[0]
get first element with test-name
class, be sure to adjust index if multiple ones.
Upvotes: 1