Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating/selecting non-standard HTML tags with jQuery, a good idea?

I've noticed that jQuery can create, and access non-existent/non-standard HTML tags. For example,

$('body').append('<fake></fake>').html('blah');
var foo = $('fake').html(); // foo === 'blah'

Will this break in some kind of validation? Is it a bad idea, or are there times this is useful? The main question is, although it can be done, should it be done?

Thanks in advance!

like image 791
maximus Avatar asked Oct 12 '22 11:10

maximus


2 Answers

You can use non-standard HTML tags and most of the browsers should work fine, that's why you can use HTML5 tags in browsers that don't recognize them and all you need to do is tell them how to style them (particularly which tags are display: block). But I wouldn't recommend doing it for two reasons: first it breaks validation, and second you may use some tag that will later get added to HTML and suddenly your page stops working in newer browsers.

like image 193
rsp Avatar answered Oct 31 '22 12:10

rsp


The biggest issue I see with this is that if you create a tag that's useful to you, who's to say it won't someday become standard? If that happens it may end up playing a role or get styles that you don't anticipate, breaking your code.

like image 34
Zikes Avatar answered Oct 31 '22 13:10

Zikes