Alex Rivera | Logout

Jquery change text between two elements

Asked 2011-11-14T06:28:46.047
13

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

for example:

<input type='checkbox' name='ch1'>
    This text must be changed !!!
<input type='checkbox' name='ch2'>

Also, I don't have any control over this Html code, so I can't add any IDs or tags.

Edit
Report

1 Answer

0

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

answered 2011-11-14T06:35:39.763

Your Answer