0

i got some li elements with a custome attribute "type".

whe i try in jquery to get the value of this attribute width jquery like so:

$("li", $list).each(function(){
    console.log($(this).attr("type"));
 });

i only get the values in firefox but not in IE 7-8

any solutions?

3
  • var $list = $("#manage_menu"); #manage_menu = the ul element. enyway if i"m trying to get lets say the ID it works fine Commented Aug 11, 2009 at 17:10
  • 1
    IE may be error'ing on the call to console.log(), which is a firebug construct. Change it to alert() and post an update. Commented Aug 11, 2009 at 17:26
  • the cosnole.log is used in IE8 wich has a console so its fine:) Commented Aug 11, 2009 at 17:27

1 Answer 1

3

type is a deprecated attribute for ul, ol, and li elements that IE still supports, along with start, value and compact. See http://www.w3.org/TR/html401/struct/lists.html#adef-type-OL.

Prefix your custom attributes with "data-". So you'd do instead:

<ul>
    <li data-type="foo">Item</li>
    <li data-type="bar">Item</li>
</ul>

and then:

$('li').each(function() {
    console.log($(this).attr('data-type'));
})

Then there won't be any reserved attribute name clashes in the future, with any browser.

See Custom Attributes in HTML 5 for more info.

Sign up to request clarification or add additional context in comments.

Comments