Is there an HTML element that is ignored during rendering?

I have this markup

<html> ... some HTML ... 

And I need to wrap it with such an element:

 <html> <div class="user-content"> ... some HTML ... </div> 

The problem is ... some HTML ... can be many different things from raw text to complex markup.

<div>

If I use a <div> , then it adds a block level break. Value if i

 Paul is cool 

now I have

 <div class="user-content"> Paul is cool </div> 

which forces a line break.

<span>

If I use <span> , then weird things start when I have a <span> containing a <div> . For example, span width is displayed as 0px, which makes javascript not too happy with node.

Is there a better tag I can use?

Some context

It's a long story. I need a node to exist in HTML, since I am running untrusted javascript, and I do not want javascript to be able to walk inside that node. To do this, we isolated all the DOM functions, and each time we call the DOM, we will check whether we work with the "user-content" node and do not allow access if we go there or to any of its children.

+6
html
source share
4 answers

I had to parse the contents to decide to use <span> or <div> . It is not perfect, but it works.

Here is my list of inline elements that help anyone

  if (starts_with($html, '<') && !starts_with($html, '<a ') && !starts_with($html, '<input ') && !starts_with($html, '<iframe ') && !starts_with($html, '<img ') && !starts_with($html, '<span ') && !starts_with($html, '<script ') && !starts_with($html, '<input>') && !starts_with($html, '<span>') && !starts_with($html, '<script>')) { 
0
source share

If your only problem with using a div is line breaks, then why not just give it a style: display: inline; ?

If you can be more specific in your problem ... Why do you need to wrap it?

Basically, a div is what you want, just tweak it accordingly.

+8
source share

You said that you have a span that contains a div. Block elements must not be contained within inline elements. However, you can use the span element inside the div.

0
source share

<span> is the closest to such an element, and the weird behavior you talked about is normal, <span> is an inline element, and <div> is a block element. You cannot put block elements inside inline ones. (display type (inline / block) is the only difference between span and a div , I think)

0
source share

All Articles