I'm trying to target all divs of a certain class and apply innerHTML. This is what I have, but I'm getting no errors and no result.
$( ".programdesc" ).innerHTML( '<p>I am alive</p>' );
Any pointers?
Join Stack Overflow to learn, share knowledge, and build your career.
I'm trying to target all divs of a certain class and apply innerHTML. This is what I have, but I'm getting no errors and no result.
$( ".programdesc" ).innerHTML( '<p>I am alive</p>' );
Any pointers?
Use the html function :
$( ".programdesc" ).html( '<p>I am alive</p>' );
div
s. I would guess that it ends up making no difference in OP's code.
– ajp15243
Dec 10 '13 at 20:26
$('div.programdesc')
. Note that if it's not a problem, it's better (faster) to just have the class in the selector.
– Denys Séguret
Dec 10 '13 at 20:28
You should use each
$( "div.programdesc" ).each(function() {
(this).innerHTML( '<p>I am alive</p>' );
});
innerHTML
is a property of a DOM Element, not a function. The property exists in pure Javascript, not in jQuery statements.
$(".programdesc").html( 'this is the jQuery way' );
document.getElementsByClassName('programdesc').index(0).innerHTML = "This is the Javascript way";
$('.certain')
will catch all particular elements whose class contains certain....Now, if he had said dynamic instead, I would agree with you.
– dockeryZ
Dec 10 '13 at 20:43
document.getElementsByClassName
simply doesn't have any innerHTML
property...
– Denys Séguret
Dec 10 '13 at 20:48