javascript - Remove self <a> tag -
this question has answer here:
- jquery replace tag tag text [duplicate] 2 answers
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
Post a Comment