Sometimes I add an attribute to some of my controls. Like:
<a href id="myLlink" isClimber="True">Chris Sharma</a>
I know it is not a valid html. But it helps me in some cases.
Is this considered as a bad practice? A friend of mine says that it is ok for Intranet environment but on internet it might not be find friendly by search engines.
If it is not a good practice, what are the best practicess?
Thanks
If you want to define your own custom attributes in HTML, you can implement them through data-* format. * can be replaced by any of your names to specify specific data to an element and target it in CSS, JavaScript, or jQuery.
You can have multiple data attributes on an element and be used on any HTML element.
The multiple attribute in HTML allows user to enter more than one value. It is a Boolean attribute and can be used on <input> as well as <select> element, To allow multiple file uploads in HTML forms, use the multiple attribute. The multiple attribute works with email and file input types.
If you are using HTML5 doctype then you can add data attrbutes which are valid.
So something like the following will be valid
<a href id="myLlink" data-isClimber="True">Chris Sharma</a>
Yes. It is considered a bad practice. Your HTML (if it's 4.0) won't validate successfully. Instead, add a class like so:
<a href id="myLlink" class="climber" >...</a>
Remember that you can have multiple classes:
<a href id="myLlink" class="climber girl pretty" >...</a>
And you can use CSS or JQuery to select out stuff based on these classes, and selectively override style based on the combinations:
a.climber { color: brown; }
a.climber.girl { color: red; }
a.climber.girl.pretty { color: pink; }
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