Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove first span element after input

Tags:

jquery

How to remove first span element after <input id="mytxt" type="textbox"/> , if it exists?

 $('#mytxt').live('change', function(){
        //TO DO    
 }
like image 523
loviji Avatar asked Dec 02 '22 23:12

loviji


2 Answers

Within your live function, do this:

$(this).next("span").remove();
like image 59
Sang Suantak Avatar answered Jan 11 '23 22:01

Sang Suantak


I think you have to check the first "SPAN" element after the element. so you have to go till the end of the document

var element = $(this).next();
while($(element)[0].tagName!="SPAN" && $(element).length!=0){
    element = $(element).next();
}
if($(element)[0].tagName=="SPAN"){
    $(element).remove();
}
like image 45
Tejasva Dhyani Avatar answered Jan 11 '23 21:01

Tejasva Dhyani