문제

I want to remove the anchor element surrounding a block of code upon page load.

When the page loads, I want this code:

<h3 class="ms-standardheader ms-WPTitle" style="text-align: justify;">
<a accesskey="W" href="#">
<nobr>
<span>Employee Announcements</span>
<span id="WebPartCaptionWPQ3"></span>
</nobr>
</a>
</h3>

To turn into this code:

<h3 class="ms-standardheader ms-WPTitle" style="text-align: justify;">
<nobr>
<span>Employee Announcements</span>
<span id="WebPartCaptionWPQ3"></span>
</nobr>
</h3>

I have tried to get this working using unwrap but I am still struggling because I want to leave the surrounding nobr elements.

도움이 되었습니까?

해결책

jQuery has an .unwrap() function that removes an element's parent.

http://api.jquery.com/unwrap/

example:

$(function() {
   $('#WebPartCaptionWPQ3').unwrap();
});

다른 팁

$(function() {
    var target = $('a[accesskey="W"]');
    var keep = target.children();
    target.replaceWith(keep);
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top