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

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -