I’ve noticed that if you take an element with jQuery you can change every attribute with the attr method. That’s what supposed to do right?
Well, it’s right but what if you do:
$('p').attr('foo','bar');
If you inspect the element with Chrome Tools or Firebug you will see that, in fact, it has now an attribute called foo with the value of bar.
Does anyone knows a way to do a previous check and avoid this? Can something go wrong if this happen?
According to the jQuery documentation,
So you could call it first like this:
$('p').attr('foo');and see if it returns an undefined value.