JavaScript How to loop through buttons in javascript? loop through buttons javascript,loop through buttons vba,loop through

$('button').on('click',function(){
    alert($(this).attr('id'));
});

Now inside the click event use the $(this) jquery object

Answer:1

Please, try this (added function doSomething(item) to explain a real usage):

    function doSomething(item) {
        switch (item.id) {
            case 'button3menu': 
                // Make this button do something, only it. For example: 
                alert('Hey, you are pressing me!');
                break;
            default:
                // Make all the button's whose id is not contemplated as a case value 
                alert('My id is: ' + item.id);
                break;
    }}

        <script>
        (function()
        {
            var num = 4;
            for (var i = 0; i < num; i++)
            {
                var elem = document.createElement('button');
                elem.id = "button" + i + "menu";
                elem.innerHTML = "button" + i;
                document.body.appendChild(elem)

                elem.addEventListener('click', function(){doSomething(this)});
            }
        })()
        </script>
Answer:2

Assuming that you have a parent element for all or some of your buttons:

<div id="parent">
<button id="button1menu">button</button>
<button id="button2menu">button</button>
<button id="button3menu">button</button>
<button id="button4menu">button</button>
<button id="button5menu">button</button>
<button id="button6menu">button</button>
</div>

A single click event listener is enough to handle all of them:

document.getElementById("parent").addEventListener("click", function(e) {
     // e.target is the clicked element
    //check if button1menu has been clicked
    if(e.target && e.target.id == "button1menu") {
        alert(e.target.id + " was clicked");
    }

    //check if button2menu has been clicked
    if(e.target && e.target.id == "button2menu") {
        alert(e.target.id + " was clicked");
    }

  //etc
 });

You can experiment more in this fiddle

This is called event delegation and its good for you

Answer:3

Just trying to get the current index of the touchable highlight that is pressed. For some reason it is only returning the highest number in the array. Any ideas? render: function() { var images = ...

Just trying to get the current index of the touchable highlight that is pressed. For some reason it is only returning the highest number in the array. Any ideas? render: function() { var images = ...

  1. react native which language
  2. react native which ide
  3. react native which database
  4. react native what is
  5. react native where is console log
  6. react native what is expo
  7. react native what is flex
  8. react native where is apk
  9. react native where to start
  10. react native what is redux
  11. react native what is props
  12. react native what is state
  13. react native what is ref
  14. react native what is a component
  15. react native where to call api
  16. react native what is promise
  17. react native what is eject
  18. react native what is await
  19. react-native what is constructor
  20. react-native what is flexbox

var a = document.createElement('a'); a.setAttribute('target','_blank'); a.click(); The above code doesn't work for me. Does setAttribute not work if the click event happens in JavaScript?

var a = document.createElement('a'); a.setAttribute('target','_blank'); a.click(); The above code doesn't work for me. Does setAttribute not work if the click event happens in JavaScript?

  1. setattribute('target' '_blank')
  2. setattribute target _blank
  3. javascript setattribute target _blank
  4. form.setattribute( target _blank )
  5. link.setattribute('target' '_blank')
  6. js setattribute target _blank

I have this function, the purpose is to find the maximum (number) element in an array, the value is coming from an argument. I'm having a hard time understanding the logic, well I'm old and slow so ...

I have this function, the purpose is to find the maximum (number) element in an array, the value is coming from an argument. I'm having a hard time understanding the logic, well I'm old and slow so ...

  1. find value array javascript
  2. find value array php
  3. find value array js
  4. find value array python
  5. find value array matlab
  6. find value array
  7. find value array excel
  8. find value array java
  9. find value array typescript
  10. find value array c#
  11. find value array jquery
  12. find value array vba
  13. find value array numpy
  14. find value array powershell
  15. find value in arraylist
  16. find array value by key php
  17. find array value in mongodb
  18. find array value in string php
  19. find array value by index
  20. find value in array of objects javascript

I have inherited a web page that has a slide show on it and I can't figure out how to change the width of the <article> containing the slide show. I think it is getting size via JavaScript, but ...

I have inherited a web page that has a slide show on it and I can't figure out how to change the width of the <article> containing the slide show. I think it is getting size via JavaScript, but ...

  1. getting width of element javascript
  2. getting width in golf swing
  3. getting width of element jquery
  4. getting width of div
  5. getting width in your golf swing
  6. getting width of an element
  7. getting width and height
  8. svg getting width