views:

70

answers:

2

Is there any parameter/function in JS that tells you if an element was closed with an ending tag? ... for this purpose.

+9  A: 

JS is simply the scripting language that provides access to the DOM of the page. The DOM is preparsed from the page source before you ever get access to it. I am fairly sure that any attempt to access the page source will return the pre-corrected source as determined by the browser during the initial parsing phase.

So in a word, no.

Nathan Ridley
Pity that browsers don't give you access to such basic validation features.
Jenko
@Jeremy: IMO, the reason is that a browser is not primarily a developer tool.
Cerebrus
+2  A: 
function getSource() {
    var xhr = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
    xhr.open('GET', window.location.href, false);
    xhr.send(null);
    return xhr.responseText;
}

Taking this approach you'd have to parse the HTML yourself - a momentous task.

J-P