2013
12.05

jQueryIt’s either I’m too dumb to understand it, or I simply underestimate it for being very easy. Yes, I am talking about jQuery’s methods in retrieving elements property/attribute.

Today was the nth time i was bitten by this error. Instead of using attr(), I used prop(). A few times I left scratching my head as my Ajax post message in Firebug’s Net Inspector shown with missing key.

So I write this post hoping that I can put rest this recurring mistakes for good (which almost immediately happened as I look at the problem deeper).

What is element’s property? What is an attribute? I found it quite difficult to answer if I based on jQuery’s documentation page on this subject. But when I look at Firebug, I immediately understand.

attr

Just look at the DOM Inspector:


firebug.dom.insp

It’s crystal clear baby! It’s kinda embarrassing to have this simple fact overlooked! Oh, I just want to add that the reason why my Ajax backend-post missing key(s) is because prop() will return undefined if the property is not found. As for attr(), it will return empty text for missing attributes.

That’s all, cheers!

GD Star Rating
loading...
How To Retrieve Elements' Attribute/Property Using jQuery, 3.0 out of 5 based on 1 rating

Incoming Search Term

Advertise Here

1 comment so far

Add Your Comment
  1. test comment