Quick question why I can't get img value from img by using onclick ?
or better yet can I use data-internalid to store some value and get it by on click ?
html
<div class="content_create"><img name="name" class='Dicon' id='Loader_images' src="src+" value="Code" onclick='getCode(this.value);'><p>typename</p></div>
JS
function getCode(_CODE){
alert(_CODE);
//getting null on here
}
Change
getCode(this.value);
to
getCode(this.attributes.value.value);
The value isn't allowed on HTML elements, except the input
elements. However, does work and as suggested, you could use getCode(this.attributes.value.value);
or getCode(this.attributes.value.textContent);
.
But I would suggest you to change the value
attribute to data-value="Code"
to make your HTML valid and then using getCode(this.dataset.value)
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.