Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-(X)HTML Attributes... any disadvantages?

I've generally tried to stick with DOM-only attributes when writing Javascript. Now that I've switched from Prototype to jQuery, I can get some serious mileage out of adding my own attributes to various DOM elements, mostly in the realm of being able to set up a very readable coding convention for handling AJAX requests.

As a short example, this means I do things like

<div type="book" app_id="13">
    <a href="#" action="delete">delete</a>
</div>

And then I can set up code to find all <a> tags with an action attribute, find a parent with a type and app_id, and then do CRUD operations... all without me having to write additional code.

Are there any pitfalls (other than not being strictly XHTML complaint) that I should watch out for, and/or any good habits I should look to emulate? How about a standard way of setting up my own attribute namespace?

like image 307
Don Werve Avatar asked Apr 22 '09 19:04

Don Werve


People also ask

What are nonstandard attributes?

Non-standard attributes can be fairly useful for passing along meta-data to Javascript however. For instance, if a link is suppose to show a popup, you can set the name of the popup in an attribute: <a href="#null" class="popup" title="See the Popup!"

How many HTML attributes are there?

HTML is the foundation of a webpage.

What is HTML attributes explain with example?

An HTML attribute is a piece of markup language used to adjust the behavior or display of an HTML element. For example, attributes can be used to change the color, size, or functionality of HTML elements. Attributes are used by including them in an opening HTML tag: <tag_name attribute_name="value">Content</tag_name>

What are properties and attributes in HTML?

Attributes are additional information which we can put in the HTML to initialize certain DOM properties. Properties are formed when the browser parses the HTML and generates the DOM. Each of the elements in the DOM have their own set of properties which are all set by the browser.


1 Answers

According to this question, using XML namespaces in XHTML 1.0 is invalid. Adding your own attributes to the same namespace seems worse to me, as they're most certainly invalid, even as far as XML goes.

Were I doing this, I'd get my mileage out of class and rel attributes. For example:

<div class="book" id="book_13">
   <a href="http://example.com/url/to/delete/non/ajaxily" class="delete">delete</a>
</div>
like image 106
Steve Pomeroy Avatar answered Sep 24 '22 04:09

Steve Pomeroy