Wednesday 15 February 2012

javascript - How can I find out whether a HTML-Tagname is Standalone -



javascript - How can I find out whether a HTML-Tagname is Standalone -

is there way find out whether html-tagname comes in pair or lone (standalone-tag)? e.g. <div></div>, <em></em>, <p></p>, ... come in pair, <br/>, <input>, <area> ... standalone.

i need function should find out if html-code snippet entered correct. hence function has investigate among others html-element can created standalone-tag. have thought how can find out if html element standalone? except illustration this:

var myarray = [ list of standalone-tags ]; if(jquery.inarray("test", myarray) != -1 ) { ... }

thanks.

browsers don't have built in list of elements defined empty.

you're reliable bet create 1 manually reading html specification.

alternatively, create element , see browser returns when convert html.

var element = prompt("what element name? e.g. br"); var container = document.createelement('div'); var content = document.createelement(element); container.appendchild(content); var reg = new regexp("/" + element); alert(reg.test(container.innerhtml) ? "not empty" : "empty");

javascript jquery html css

No comments:

Post a Comment