I want to access the value of the HTML title attribute as a variable for the onclick function.
This is an example for my HTML elements:
<a title="id:4" onclick="openWin(4)">example</a>
This is my JavaScript function:
function openWin(number)
{
window.open("http://www.some-example.org/some/example/id:"+number)
}
This works but since I have a lot of HTML elements, I'd like to find a way to reference the title value inside the openWin() function instead of writing "openWin(someNumber)". Do you have any ideas how to do this?
Any help would be much appreciated!
openWin(this)andel.attr('title')titleattribute is not meant to store program data, but human readable descriptions to the current element. If you need to assign some chunk of data to an HTML element use thedata-*attributes instead.