Jump to content

how make many id in one getElementById


Recommended Posts

Hi, i make one but it will be many line same, like this with 20.

document.getElementById("Test1").value = Dotoff;
document.getElementById("Test2").value = Dotoff;
document.getElementById("Test3").value = Dotoff;

i wonder can it make all id in one? i tried it:
 

document.getElementById("Test1","Test2","Test3").value = Dotoff;


but it didn't work well, only Test1 change.
some know how make all 20 in one? it can save me lots space/line ;)

Link to post
Share on other sites

Then too, you could use jQuery, it will do the counting for you.

document.getElementById("Test1").value = Dotoff;
document.getElementById("Test2").value = Dotoff;
document.getElementById("Test3").value = Dotoff;

<element1 class='test'></element1>
<element2 class='test'></element2>
<element3 class='test'></element3>

$('.test').val('Dotoff');

Roddy

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...