Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery change text nested in div, paragraph tag and strong tag

I'd like to be able to reach out into the following html structure

 <div id="collection_propID214_formID1">
   <p class="fieldHeaderContainer">
       <strong>Add by ID:</strong>
   </p>
 </div>

And change the text inside of tag, using jQuery. Is this possible?

like image 749
user2917629 Avatar asked Aug 26 '14 18:08

user2917629


People also ask

How to get value in b tag in jQuery?

We can use the jQuery text() function to get the value of the bold tag. If we want to get values of all bold tags then we can use each() loop that will select all bold tags one by one.

How to make text bold in jQuery?

addClass("boldText"); *Note about the use of ! important : This is usually not recommended CSS as it's often used in the wrong way. However in this case if you add a class called boldText to an element, chances are, you will always want it to have bold text.

How do I get just the text from HTML in jQuery?

You could use $('. gettext'). text(); in jQuery.


1 Answers

You could change the text of the strong tags inside the div using .text().

Try this:

$('#collection_propID214_formID1 strong').text('Your text here');

JSFiddle Demo

Or

$('#collection_propID214_formID1').find('strong').text('Your text here');

P.S: If there are more than one strong elements, this would change the text for all.

like image 199
imbondbaby Avatar answered Oct 20 '22 00:10

imbondbaby