Metoda hasAttribute
Metoda hasAttribute kontrollon praninë
e një atributi të caktuar në një element. Nëse atributi
ekziston - do të kthejë true, nëse jo - do të kthejë false.
Sintaksa
javascriptelement.hasAttribute(emri i atributit);
Shembull
Le të kontrollojmë praninë e atributit value
në element:
html<input id="elem" value="abcde">javascriptlet elem = document.querySelector('#elem');
console.log(elem.hasAttribute('value'));
Rezultati i ekzekutimit të kodit:
javascripttrue
Shembull
Tani atributi value nuk ekziston:
html<input id="elem">javascriptlet elem = document.querySelector('#elem');
console.log(elem.hasAttribute('value'));
Rezultati i ekzekutimit të kodit:
javascriptfalse
Shihni gjithashtu
-
metoda
getAttribute,
e cila merr atributet -
metoda
setAttribute,
e cila shkruan atributet -
metoda
removeAttribute,
e cila fshin atributet