Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple HTML Dom: How to remove elements?

I would like to use Simple HTML DOM to remove all images in an article so I can easily create a small snippet of text for a news ticker but I haven't figured out how to remove elements with it.

Basically I would do

  1. Get content as HTML string
  2. Remove all image tags from content
  3. Limit content to x words
  4. Output.

Any help?

like image 232
kasakka Avatar asked Nov 22 '11 13:11

kasakka


People also ask

How do you remove an element in HTML?

Approach: Select the HTML element which need to remove. Use JavaScript remove() and removeChild() method to remove the element from the HTML document.

How do you get rid of elements?

Use offsetWidth & offsetHeight properties of the DOM element to get its the width and height.

Which property should be used to remove an element from DOM?

The removeAttribute() method removes an attribute from an element.


1 Answers

There is no dedicated methods for removing elements. You just find all the img elements and then do

$e->outertext = ''; 
like image 151
Gordon Avatar answered Oct 23 '22 23:10

Gordon