How do you change the text for all within the a
to
continue reading
using jquery
<div class="post-read">
<a href="http://www.google.com">Read More</a>
</div>
Using CSS, you can center text in a div in multiple ways. The most common way is to use the text-align property to center text horizontally. Another way is to use the line-height and vertical-align properties. The last way exclusively applies to flex items and requires the justify-content and align-items properties.
innerText returns all text contained by an element and all its child elements. innerHtml returns all text, including html tags, that is contained by an element.
The textContent property returns: The text content of the element and all descendaces, with spacing and CSS hidden text, but without tags.
Do it with jQuery inside of a document ready handler ($(fn)
)...
$('.post-read a').text('continue reading');
jsFiddle.
For the sake of it, here is how to do it without jQuery....
var anchor = document.getElementsByClassName('post-read')[0].getElementsByTagName('a')[0],
textProperty;
if (anchor.textContent) {
textProperty = 'textContent';
} else if (anchor.innerText) {
textProperty = 'innerText';
}
anchor[textProperty] = 'continue reading';
jsFiddle.
This will work good for your piece of HTML, but it isn't too generic.
If you don't care about setting innerText
property, you could use...
anchor.textContent = anchor.innerText = 'continue reading';
I wouldn't recommend it though.
This should do it:
$('.post-read a').html('continue reading');
$('.post-read a').html("continue reading")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With