how to change text value within an element?

后端 未结 4 710
野的像风
野的像风 2021-01-01 18:36

How do you change the text for all within the a to

continue reading

using jquery

相关标签:
4条回答
  • 2021-01-01 19:01
    $('.post-read a').html("continue reading")
    
    0 讨论(0)
  • 2021-01-01 19:08

    This should do it:

    $('.post-read a').html('continue reading');
    
    0 讨论(0)
  • 2021-01-01 19:10

    Through the text property in jQuery that changes the inner text of the <tag>

    $(document).ready(function () {
        $('.postread a').text("your new text here ");
    }
    
    0 讨论(0)
  • 2021-01-01 19:19

    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.

    0 讨论(0)
提交回复
热议问题