Vinod Sebastian – B.Tech, M.Com, PGCBM, PGCPM, PGDBIO

Hi I'm a Web Architect by Profession and an Artist by nature. I love empowering People, aligning to Processes and delivering Projects.

Advertisements

Accessing Elements in JavaScript

When working with JavaScript, accessing elements in the Document Object Model (DOM) is a crucial aspect. Various methods facilitate this process:

  • getElementBy: This method enables the selection of elements based on different criteria like class name, tag name, or attribute values.
  • getElementById(Id): Specifically used to retrieve an element by its unique ID, which should be distinct within the document.
  • getElementsByName(Name): When elements share the same name attribute, this method returns a collection of all such elements.
  • getElementsByTagName(TagName): This method selects all elements with the specified tag name. Using “*” as the tag name represents all elements. Note that tag names are case-sensitive, and consistency in using lowercase is recommended.
  • DomObject.childNodes(): This property provides a collection of child nodes of a DOM object. Each node can be an element node, attribute node, or text node. Elements are identified by a nodeType of 1, distinguishing them from other node types.

Reloading a Page in JavaScript

Dynamic page refreshing or reloading is a common necessity in web development. JavaScript offers several methods to achieve this functionality:

  • location.href = "location.href": Setting the location.href property to its own value triggers a page reload at the current location.
  • location.reload(): Invoking the reload() method on the location object reloads the current page, fetching updated content from the server.
  • history.go(0): The go() method of the history object facilitates navigation through session history. Providing 0 as an argument reloads the current page, similar to a refresh action.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x