How to use this script with multiple ids? Does not work on the second id that I try to add
<script type="text/javascript">
window.onload = (function () {
var elem = document.getElementById("id1","id2").onclick = function()
{
fbq('track', 'InitiateCheckout');
}
});
</script>
You can use querySelectorAll to select many items by their IDs:
var items = document.querySelectorAll('#id2, #id3, #id5');
for (var i = 0; i < items.length; i++)
{
items[i].onclick = function() {
this.innerText = this.innerText + '!';
};
}
2, 3, 5 are working:
<p id="id1">I am 1</p><p id="id2">I am 2</p><p id="id3">I am 3</p><p id="id4">I am 4</p><p id="id5">I am 5</p>
However, creating a common class sounds much better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With