Jquery change text between two elements

后端 未结 8 936
無奈伤痛
無奈伤痛 2020-12-06 10:48

I want to change text between two elements using JQuery, but I don\'t have any idea !

for example:


    T         


        
相关标签:
8条回答
  • 2020-12-06 11:13

    You use js replace function to substitute the text you want to replace Here is the example: http://jsfiddle.net/yangchenyun/8zFFc/

    Here is the code

    var replacedText = $('input[name=ch1]').parent().html().replace('This text must change !!!', 'replaced text');
    
    $('input[name=ch1]').parent().html(replacedText);
    
    0 讨论(0)
  • 2020-12-06 11:14

    You can use paragraph

    for the text as below

    <input type='checkbox' name='ch1'>
    <p id="change_text"> This text must change !!!</p>
    <input type='checkbox' name='ch2'>
    

    in jquery use

    $("#change_text").html(" Your text here ");
    
    0 讨论(0)
  • 2020-12-06 11:17

    Are the 2 inputs in a bigger container div? Then you could se-set that divs innerHTML without the text inbetween

    0 讨论(0)
  • 2020-12-06 11:20

    Can you ad a span like this?

    <input type='checkbox' name='ch1'>
    <span id="change"> This text must change !!!</span>
    <input type='checkbox' name='ch2'>
    
    0 讨论(0)
  • 2020-12-06 11:22

    this might be helpful for you:

    http://api.jquery.com/nextUntil/

    0 讨论(0)
  • 2020-12-06 11:22

    I think you can try contents() to select the text node next to the checkbox you want and remove it.

    However, I think it might not work in IE6/7.

    try this

    $(function(){
    $('input:checkbox').parents().contents()
    

    .filter( function(index){return (this.nodeType === 3 && $('input:checkbox').parents().contents().eq(index-1).attr('name') === 'ch1' ); }).remove(); });

    Check out the result here

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