I have a site I'm working on where I want to mark if a row of data has been changed. If something has been changed in that row I would mark it with a custom attribute like so.
<tr>
<td isDirty="true">
....row data
<td>
</tr>
This works great with jQuery and it doesn't add to much code to my page.
But is this really the correct way of doing something like this and what are the downsides?
I guess another way of doing this would be like this, but it seems like over kill.
<tr>
<td>
....row data
<input id="isDirty" type="hidden" value="true" />
<td>
</tr>
Custom attributes are attributes that are not part of the standard HTML5 attributes but are explicitly created. They allow us to add our own information to HTML tags. These are not specific and can be used with all the HTML elements.
Custom tags are not valid in HTML5. But currently browsers are supporting to parse them and also you can use them using css. So if you want to use custom tags for current browsers then you can. But the support may be taken away once the browsers implement W3C standards strictly for parsing the HTML content.
You can use getAttribute() and setAttribute() in JavaScript to get and set the value of different data attributes. The getAttribute method will either return null or an empty string if the given attribute does not exist. Here is an example of using these methods: var restaurant = document.
HTML attributes can be used to change the color, size, and other features of HTML elements. For example, you can use an attribute to change the color or size of a font for a text element or the width and height for an image element.
Why don't you use the jQuery data capability?
Your example will be (I don't know the condition to select proper td):
$("tr td").data("isDirty", true);
take a look at documentation
Technically you should be using the class attribute for this. Tags can have more than one class so it shouldn't affect anything
<td class="isDirty otherclass">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With