+44 (791) 5698 086

JavaScript Tips

This post will be updated with various javascript related tips which are not extensive enough to have their own post.

How to Select any element and change its any property

You can access any element using javascript by calling it through its different attributes, in various ways, like:

document.getElementsByName('yourname')[0]; // adding zero means the first one out of all

Or:

document.getElementById('yourname'); // there can be only 1 id per page

And to alter any attribute of this element, smiply use setAttribute function.

E.g. to change the value property of an element with Id ‘myelement’, we can use this code:

document.getElementById('myelement').setAttribute("value", "our new value");

The attribute that we’re trying to set can be anything, any randomly generated attribute name too.

Leave a Reply

Your email address will not be published. Required fields are marked *

Who are we?

Nabtron team includes web, desktop software and mobile apps developers along with SEO professionals.

We are available 24 hours, 7 days a week. Contact us now for anything you need!

Join our mailing list

Lets become friend :) What's your name & email?