I want to change text between two elements using JQuery, but I don\'t have any idea !
for example:
T
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);
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 ");
Are the 2 inputs in a bigger container div? Then you could se-set that divs innerHTML without the text inbetween
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'>
this might be helpful for you:
http://api.jquery.com/nextUntil/
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