i have multiple button created dynamically from DB which holds id and Value, i have called a class function through EventHandler which works only for the first button, How to call class functions from onclick
<button data-add-tab id="51200844-100-RP" value="data_source" onclick="chromeTabs.addTab({title: 'New Tab',this.id,this.value,favicon: false});">Add new tab</button>
<button data-add-tab id="51200520-483-RP" value="data_source1" onclick="chromeTabs.addTab({title: 'New Tab',this.id,this.value,favicon: false});">Add new tab</button>
<button data-add-tab id="51200884-103-RP" value="data_source2" onclick="chromeTabs.addTab({title: 'New Tab',this.id,this.value,favicon: false});">Add new tab</button>
here is my script which works on even handler
<script>
var chromeTabs = new ChromeTabs()
document.querySelector('button[data-add-tab]').addEventListener('click', _ => {
chromeTabs.addTab({
title: 'New Tab',
id:_.target.id,
value:_.target.value,
favicon: false
})
})
can you please Help me Thanks.
querySelector()selects the first element matching the query string. Check outquerySelectorAll(), which returns all elements matching the query string. Note that you can't chain.addEventListenerto this. You'll have to iterate and attach them one-by-one, or use event delegation. More information...onclickis never a good idea.onclick="call(this.id,this.value)"in script asfunction call(id,value){chromeTabs.addTab({val1,val2,val3val4}); }is its possible to avoid call funtion >