Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
163 views
in Technique[技术] by (71.8m points)

javascript - Remove dynamically inserted code

I discovered the following code in my page source. It is probably the hand of a plugin that I am using. I tried to remove it with jQuery but it did not work. Can you give me any suggestions about how should I go about removing it? I tried to select it with the unique selector + .remove() but it did not work.

<div style="position: absolute; top: -136px; overflow: auto; width: 1241px;">
    <h3>
        <strong>
            <a href="http://shopgiaynu.vn" style="font-size: 11.335pt;">shop giày n?</a>
        </strong>
        <strong>
            <a href="http://thoitrangf5.vn" style="font-size: 11.335pt;">th?i trang f5</a>
        </strong>
        <strong>
            <a href="http://themestotal.com/tag/responsive-wordpress-theme" style="font-size: 11.335pt;">Responsive WordPress Theme</a>
        </strong>
        <em>
            <a href="http://2xaynha.com/tag/nha-cap-4-nong-thon" style="font-size: 10.335pt;">nha cap 4 nong thon</a>
        </em>
        <em>
            <a href="http://2giaynu.com/giay-nu/giay-cao-got-giay-nu" style="font-size: 10.335pt;">giay cao got</a>
        </em>
        <em>
            <a href="http://2giaynu.com" style="font-size: 10.335pt;">giay nu 2015</a>
        </em>
        <em>
            <a href="http://2xaynha.com/tag/mau-biet-thu-dep">mau biet thu dep</a>
        </em>
        <em>
            <a href="http://fsfamily.vn/lam-dep/toc-dep">toc dep</a>
        </em>
        <em>
            <a href="http://ihousebeautiful.com/">house beautiful</a>
        </em>
        <em>
            <a href="http://2giaynu.com/giay-nu/giay-the-thao" style="font-size: 10.335pt;">giay the thao nu</a>
        </em>
        <em>
            <a href="http://2giaynu.com/giay-nu/giay-luoi-2" style="font-size: 10.335pt;">giay luoi nu</a>
        </em>
        <em>
            <a href="http://phunuz.com" style="font-size: 10.335pt;">t?p chí ph? n?</a>
        </em>
        <strong>
            <a href="http://hardwareresourcesnew.com/">hardware resources</a>
        </strong>
        <strong>
            <a href="http://shopgiayluoi.com/">shop giày l??i</a>
        </strong>
        <strong>
            <a href="http://www.thoitrangnamhanquoc.vn/">th?i trang nam hàn qu?c</a>
        </strong>
        <strong>
            <a href="hhttp://giayhanquoc.com/">giày hàn qu?c</a>
        </strong>
        <strong>
            <a href="http://giaynam.pro/">giày nam 2015</a>
        </strong>
        <strong>
            <a href="http://shopgiayonline.com/">shop giày online</a>
        </strong>
        <strong>
            <a href="http://aosomihanquoc.vn/">áo s? mi hàn qu?c</a>
        </strong>
        <strong>
            <a href="http://f5fashion.vn/">f5 fashion</a>
        </strong>
        <strong>
            <a href="http://thoitrangf5.vn/">shop th?i trang nam n?</a>
        </strong>
        <strong>
            <a href="http://diendannguoitieudung.com/">di?n ?àn ng??i tiêu dùng</a>
        </strong>
        <strong>
            <a href="http://diendanthoitrang.edu.vn/">di?n ?àn th?i trang</a>
        </strong>
        <strong>
            <a href="http://giaythethaonuhcm/">giày th? thao n? hcm
            </a>
        </strong>
    </h3>
</div>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use href attribute selector if the URL is same and unique on the page.

Make sure you execute this script after HTML is loaded into DOM

Check anchor tag and remove closet div.

$('a[href="http://shopgiaynu.vn"]').closest('div').remove();

DEMO


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...