I want to have a jQuery/PHP site that uses <span>
elements for the navigation links. I need to have a value
attribute to use
$(".navLink").click(function() {
window.location.href = "/index.php?page=" + this.value //or whatever
});
I can't use this.id
because it conflicts with other HTML elements. Is there any way to create and use a "dummy" HTML attribute?
Use a data-* attribute. Something like data-href would be good. jQuery gives you a nice interface for reading the values.
this.data('href')
will read the value of
data-href="some.value"
See http://api.jquery.com/jquery.data/ for more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With