1

I sometime use undefined attribute.


Example

<ul>
  <li id="goFirst" url="abcd.jsp">menu1</li>
  <li id="goSecond" url="abcd2.jsp">menu2</li>
</ul>

By using attribute("url"), I could easily access attribute by jQuery.

Usage in jQuery

var url = $("#goFirst").attr(url);
location.href="url";

However, I'm not sure whether this is right way to use or non-standard way.

Sorry for my English. thanks

Patrick Jeon
  • 1,684
  • 5
  • 24
  • 31

1 Answers1

7

Use data-url instead, this is valid HTML.

<li id="goFirst" data-url="abcd.jsp">

Then you can use:

var url = $("#goFirst").attr("data-url");

Or:

var url = $("#goFirst").data("url");
Curtis
  • 101,612
  • 66
  • 270
  • 352
  • `data-*` attributes [can be used even if it isn't HTML5](http://caniuse.com/#search=datase) – Joseph May 09 '12 at 09:50