greddin
asked on
How do a replace text within a specific span class where multiple span classes of the same name exist?
For example, if my page has several spans like this:
<span class="ms-formdescription" >Enter the website address:</span>
<span class="ms-formdescription" >Type the description:</span>
How do I replace only the span with "Type the description:" with "Enter the name of the site:"?
I've tried this but it doesn't work:
$('span.ms-formdescription ').filter( function () { return $(this).text() === 'Type the description:' }).text('Enter the name of the site:');
Thanks for your help!
<span class="ms-formdescription"
<span class="ms-formdescription"
How do I replace only the span with "Type the description:" with "Enter the name of the site:"?
I've tried this but it doesn't work:
$('span.ms-formdescription
Thanks for your help!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, I have it now. This works:
$("span.ms-formdescription :contains( 'Type the description:')").text("Thi s is the new text");
Thanks for your help.
$("span.ms-formdescription
Thanks for your help.
ASKER
I'm good now. Thanks.
ASKER
I should have showed this as my code before. What I have actually looks like this:
<span dir="none">
<span class="ms-formdescription"
<span class="ms-formdescription"
</span>
Right now the selector is replacing everything within the upper span tag. Is there a way to match just the second span containing "Type the description:"?
Thanks again.