browse by category or date

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

Possibly relevant:

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Incoming Search

html, javascript, jquery

1 comment so far

Add Your Comment
  1. test comment