How do I remove an HTML element from a webpage using javascript? (Trying to make a chrome extension)
Asked
Active
Viewed 144 times
0
-
1What code are you using to do the delete? – Bidhan Apr 03 '16 at 03:56
-
Ill edit my post in a sec – 2mandude Apr 03 '16 at 04:03
-
1It's seem duplicated here http://stackoverflow.com/questions/5933157/how-to-remove-an-html-element-using-javascript – Davuz Apr 03 '16 at 04:28
-
Yea I tried using his implementation but I still couldn't get anything from the website to be deleted – 2mandude Apr 03 '16 at 05:01
-
1Take a look at https://developer.chrome.com/extensions/content_scripts and http://stackoverflow.com/questions/9602022/chrome-extension-retrieving-gmails-original-message – Paul S. Apr 03 '16 at 14:06
-
you must include the problem and code in the question itself – Zig Mandel Apr 03 '16 at 14:40
1 Answers
0
Take a look at :contains selector, you can use the following code.
$("p:contains('iPhone')").closest("div.box").remove();
p:contains('iPhone')
will get all <p>
which contains iPhone in it text, while closest("div.box")
will get the first div
with class box
, then remove
will remove the div
as well as everything inside it.

Haibara Ai
- 10,703
- 2
- 31
- 47