javascript - Create a List of button with generic id's in order to get any of them with getElementById. (Id dinamically) -


i want create dynamically id's of buttons list of buttons, in order of button using getelementbyid.

an example of code using same id :

 @foreach (var cat in model) {      <div class="list-group">          <button id="namecategory" onclick="onclickseeproducts()" >@cat.name</button>      </div>  } 

the function onclickseeproducts should looks :

function onclickseeproducts() {     button = document.getelementbyid("namecategory").innerhtml;     //something  } 

ids must unique, since buttons have same id, there no way know button want target use of id.
easier way pass button argument function.

... onclick="onclickseeproducts(this)" ... ... function onclickseeproducts(button) { ...    msg = button.innerhtml; ... 

Comments

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -