javascript - Remove self <a> tag -


this question has answer here:

i have litte bug, in menu there's links has no hrefs (like empty link). if has no href, want remove keep text.

this got:

$('.mainmenu a, .mainmenu *').each(function(){     var href = $(this).attr('href');     if(!href)     {         console.log($(this).html());         //remove <a> element, how?     } }); 

help please?

you need unwrap contents then

$('.mainmenu a:not([href])').contents().unwrap() 

:not filter out elements without href tag

.contents() returns jquery object contains contents - text

.unwrap() removes anchor tag around it


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -