Is there a way to pass the value attribute from HTML side to JavaScript function via onclick event?
html/php
echo '<a href="#" class="ListOfStuff" value="' . $varVal . '" onclick="doFunction(this.value)"></a>';
javascript
<script>
doFunction(value){
alert(value);
}
</script
this.value is undefined. This.id is the way I've handled it in the past, but now that i am dynamically writing a list with classnames, I don't quite understand how to pass the value from the HTML. This = [object OBJECT] and this.value is undefined. I can get the value if i use ID but not class. what am i doing wrong?
onClick=doFunction(event)and then writingalert(event.target.value);in your Javascript?event.target = javascript:void(0);andevent.target.value = undefinedonclick=doFunctionandfunction doFunction(event) {alert(event.target.value);}