javascript - Accessing HTML attributes inside Listener Function -
i'm trying access custom html attribute within function attached event listener far have been unable work. i'm not sure how correctly reference target element.
currently have:
<td id= "kayak1" data-picid="1"><img src= "thumbnail.jpg"></td> a listener:
var cat1 = document.getelementbyid("kayak1"); cat1.addeventlistener("dblclick", showcatpix); and function:
function showcatpix () { var picselect = this.getattribute("data-picid"); switch(picselect) { case 1: var catpix = document.getelementbyid("showcatpics"); catpix.src ="cat_kayak.jpg"; break; } } the event calling function correctly showcatpix isn't accessing picid attribute , nothing being displayed. tried using this.dataset.picid. didn't work either. tips on how correctly reference property great.
the picselect retrieved dom attribute string "1", while in switch statement comparing number 1. , switch/case === comparison.
using this not issue, should work.
Comments
Post a Comment