Dambo
Dambo

Reputation: 3486

How to change the content of all the tags with the same class?

I am trying to use JQuery to change the content of all the .valueInput tags with a string. Here is my code, which doesn't seem to do anything:

fiddle: https://jsfiddle.net/p4yvq0vp/2/

html

<div class='main'>
  <span class='valueInput'></span>
  <span class='valueInput'></span>
  <span class='valueInput'></span>
</div>

jquery

$document.ready(function() {
  $('.valueInput').text('hi');
});

Upvotes: 0

Views: 43

Answers (2)

Jonathan Borges
Jonathan Borges

Reputation: 1069

Solution:

$(document).ready(function() {
  $('.valueInput').each(function() {
    $(this).text('hi!');
  });
});

https://jsfiddle.net/vuz5ygur/

Upvotes: 1

31piy
31piy

Reputation: 23859

Change $document to $(document).

Upvotes: 2

Related Questions