Echivalentul hasAttr() in jQuery

postat acum 3 ani de Stefanescu Mihai in categorie jQuery

In jQuery nu exista functia hasAttr(), asa ca iata cum puteti obtine aceasta functioenalitate.

Preia atributul si verifica valoarea

var attr = $(this).attr('name');

// For some browsers, `attr` is undefined; for others, `attr` is false. Check for both.
if (typeof attr !== typeof undefined && attr !== false) {
  // Element has this attribute
}

In JavaScript nativ

$(this)[0].hasAttribute("name");

jQObject[0].hasAttribute("name");

Filtrare selectie

$(this).is('[name]');

$(this).filter("[name='choice']");

 

Sunt un tanar programator din Bucuresti ce lucreaza in PHP/Mysql (MySqli/PDO), Laravel, CodeIgniter, MySQL, PostgreSQL, Wordpress, HTML5/CSS3, Sass, Photoshop si multe altele.
Google+ Community Facebook Group