I have a requirement where I need to set html input tags ids with js variables.
example:
<input type='text' id='(here I need js variable)'/>
I know there's a way to do that by creating entire element by
document.createElement('div name');
and I can append to the div, but I want it in a simple way.
If it is a Java variable then I can do it like
<%String myVar = "txtId"%>
<input type='text' id='<%= myVar%>'/>
Is there any simplest way to put a js variable in a html tag?
Update :
Thanks for the answers guys, I know we can create any number of input elements and append to the parent element. And also we could get an element by tag name and can set id for those elements.But my question is, is there a way to use(or) place (or) insert a js variable in html tag just like we could insert a java variable in the html tag as I've shown above.
like,
<script>
var txtId = 'txt1';
</script>
<html>
<input type='text' id='document.write(txtId)'/>
</html>
Is there a way to do like this?