Systematic HTML tags validation
Is there an offline tool that can verify whether certain tags possess particular attributes?
I'm looking for something that can verify that all:
form
tags have aname
attribute.div
, andspan
tags have at least anid
orclass
attribut开发者_如何学编程e.
Does tidy have an obscure option where you could specify such things?
simply and quickly you can do your validations like this if jQuery is available on your page.
$('form').each(function(){ if ($(this).attr('name') === undefined) { alert('There is at least one form with no name.'); } }); $('div').each(function(){ if ($(this).attr('id') === undefined) { alert('There is at least one div with no id.'); } });
also this is a non-jQuery solution example
var arr = document.getElementsByTagName('div'); var flag = false; for (var i = 0, len = arr.length; i < len; i++) { if (arr[i].getAttribute('id') == null) { flag = true; break; } } if (flag) { alert('There is at least one div with no name.'); }
精彩评论