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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -