Taj Mohammed
Taj Mohammed

Reputation: 1

Change or convert only text of label without changing their values in form

This is my code below:

<form name="mainform" id="mainform" class="form_step" action="" method="post" enctype="multipart/form-data">
<ol>
<li id="list_cp_you_are">
 <div class="labelwrapper">
    <label><a href="#" tip="You are" tabindex="999"><div class="helpico"></div></a>You are: <span class="colour">*</span></label>
 </div>

Expected code:

<form name="mainform" id="mainform" class="form_step" action="" method="post" enctype="multipart/form-data">
<ol>    
    <li id="list_cp_you_are">
 <div class="labelwrapper">
    <label><a href="#" tip="You are" tabindex="999"><div class="helpico"></div></a>I am: <span class="colour">*</span></label>
 </div>

I just want to convert or change only "You are:" text to "I am:" text from label tags without changing their values that too with immediate effect on page loading.

Anyone plz helpme..

Upvotes: 0

Views: 169

Answers (1)

adeneo
adeneo

Reputation: 318352

Get the anchor and the textNode will be the nextSibling :

$('#mainform label a').each(function() {
    this.nextSibling.nodeValue = this.nextSibling.nodeValue.replace('You are', 'I am');
});

FIDDLE

Upvotes: 2

Related Questions