Hi all,
You can make your own custom attribute using data-. It allows possessive exchanged information between HTML and its DOM representation. It can work with javascript also, every browser will let you fetch and modify data- attributes using the getAttribute and setAttribute methods,
Example with css -
css :-
section [data-index='123'] {
color:red;
width:200px;
}
HTML :-
<section data-index="123">
data attribute
</section>
Example with javascript-
Html :-
<p onclick="showDetails(this)" id="tarantula" data-car-type="spider">Honda city</p>
script :-
function showDetails(car) {
var carType = car.getAttribute("data-car-type");
alert("This " + car.innerHTML + " is a " +carType + ".");
}
0 Comment(s)