Skip to content Skip to sidebar Skip to footer

Get Attribute Of Clicked Link With Js Function

there is html structure: no I need to get attribute of a,that had been clicked,e.g. alt. How to know with setStrin

Solution 1:

onclick="setString(this)

///Javascript Code:

functionsetString(element){

var value = element.children[0].alt;

}

Solution 2:

I would change my HTML to remove the bits that aren't needed...

<imgalt="no"onclick="setString(this.alt);" />

Rather than wrapping the image in an anchor tag, style it with CSS if you want...

cursor: pointer;

Post a Comment for "Get Attribute Of Clicked Link With Js Function"