jessiPP
jessiPP

Reputation: 446

dom traversal using jquery

I have this html and want to traverse the dom and place a value in the span that has the

class="center" 

after the page is loaded using jquery. I must take into consideration that the are other html on the same page with same structre as this. The only difference is that each of them has a unique td id. Here is the html:

<table>
 <tr>
 <td id="bankname">
  <div unselectable="on" style="-webkit-user-select: none; -webkit-tap-highlight-color:
   rgba(255, 255, 255, 0); width: 66px; " class=" select-area select-modify_select  
   select-focus ">
   <span class="left"></span>
   <span class="center">B.N.S.</span>
   <a class="select-opener"></a>
  </div>
 </td>
<tr>
</table>

Upvotes: 0

Views: 89

Answers (3)

Sushanth --
Sushanth --

Reputation: 55740

$('#bankname span.center').text('Hello World!!');

I prefer .html() here as it is a bit faster than .text()

$('#bankname span.center').html('Hello World!!');

Upvotes: 0

Diode
Diode

Reputation: 25135

$('#bankname span.center').text( newValue );

Upvotes: 1

moonwave99
moonwave99

Reputation: 22817

$(function(){
    $('#bankname span.center').text( theValueYouWant );
});

This way you search for a <span> tag having center class inside #bankname element.

Upvotes: 1

Related Questions