javascript - getElementsByClassName get single element -
i need add eventlistener function on every div class, tried this:
var = document.getelementsbyclassname('linkto'); (var = 0; i<a.length;i++) { a[i].addeventlistener('click',function(){ console.log(a); }); }
but gives me divs. divs generated in foreach loop:
@foreach($faqs['my_stay'] $faqheading) <div class="row lowboarder linkcolor-darkblue linkto"> {{ link_to('#div'.$faqheading->id,$faqheading->heading) }} </div> @endforeach
is there way determine div clicked on?
try below, "this" inside click function refer clicked div
for (var = 0; i<a.length;i++) { a[i].addeventlistener('click',function(){ console.log(this.innertext); }); }
Comments
Post a Comment