javascript - can I pass dynamic id to document.getElementById(""); -


i have 2 id li element

  1. listitem1

  2. listitem2

in javascript can pass these 2 id dynamically document.getelementbyid("");

getelementbyid() method other, , therefore might provide variable containing string argument.

var identifier = "listitem1"; document.getelementbyid(identifier); 

but might consider using classes instead of ids if want address multiple instances...


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -