By Cracker0dks

2013-05-23 13:36:43 8 Comments

Try this at your JavaScript console (Chrome or something) with jQuery.

var jo = $("<xml required=\"true\" name=\"lol\"></xml>"); //test xml
jo.attr("required"); //returns "required" instead of true
jo.attr("name"); //returns correct "lol"
jo.prop("required"); //returns undefined
jo.prop("name"); //returns undefined

Anyone out there with a working solution to get the correct required value (true/false) of this xml?

.prop() only works with html like <input>.


@Pointy 2013-05-23 13:44:56

The jQuery code has its own opinions on attributes and their nature, based on their names and semantics from the HTML world. That's why "required" gives you "required" as its attribute value.

You can try using .getAttribute() directly, though its results might be browser-dependent:


The .prop() function only works for HTML DOM elements because it relies on the browser creating objects with properties reflecting attribute values parsed from the source.

Related Questions

Sponsored Content

23 Answered Questions

[SOLVED] Loading local JSON file

17 Answered Questions

[SOLVED] How do I parse XML in Python?

  • 2009-12-16 05:09:24
  • randombits
  • 1274049 View
  • 1017 Score
  • 17 Answer
  • Tags:   python xml

18 Answered Questions

[SOLVED] .prop() vs .attr()

13 Answered Questions

[SOLVED] What does <![CDATA[]]> in XML mean?

  • 2010-05-06 20:20:50
  • dontWatchMyProfile
  • 1248090 View
  • 1022 Score
  • 13 Answer
  • Tags:   xml cdata

14 Answered Questions

[SOLVED] How to define multiple CSS attributes in jQuery?

  • 2009-01-15 15:35:29
  • Edward Tanguay
  • 595377 View
  • 508 Score
  • 14 Answer
  • Tags:   jquery css

30 Answered Questions

[SOLVED] How do you parse and process HTML/XML in PHP?

4 Answered Questions

[SOLVED] jQuery attr vs prop?

12 Answered Questions

[SOLVED] Prevent RequireJS from Caching Required Scripts

4 Answered Questions

[SOLVED] Why jQuery 1.9+ attr() method not deprecated?

Sponsored Content