Accessing DOM

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 157:- Accessing DOM

To access and manipulate the DOM (Document Object Model), you can use JavaScript. In the browser environment, the global document object represents the web page in the browser's window. You can use the document object to select and manipulate elements on the page.

Here are some examples of how to access the DOM using JavaScript:

  1. Select an element by its ID:

javascriptCopy code

const element = document.getElementById('myId');

  1. Select an element by its tag name:

javascriptCopy code

const elements = document.getElementsByTagName('p');

  1. Select an element by its class name:

javascriptCopy code

const elements = document.getElementsByClassName('myClass');

  1. Select an element using a CSS selector:

javascriptCopy code

const element = document.querySelector('#myId'); const elements = document.querySelectorAll('.myClass');

Once you have selected an element, you can manipulate its properties, such as its text content, HTML content, attributes, and CSS styles. Here are some examples:

  1. Set the text content of an element:

javascriptCopy code

element.textContent = 'Hello, world!';

  1. Set the HTML content of an element:

javascriptCopy code

element.innerHTML = '<strong>Hello, world!</strong>';

  1. Get or set the value of an input element:

javascriptCopy code

const input = document.getElementById('myInput'); const value = input.value; input.value = 'new value';

  1. Get or set the attribute of an element:

javascriptCopy code

const link = document.getElementById('myLink'); const href = link.getAttribute('href'); link.setAttribute('href', 'http://example.com');

  1. Get or set the CSS style of an element:

javascriptCopy code

element.style.color = 'red'; element.style.fontSize = '20px';

18. Understanding DOM

Comments: 2

profile
@niteshguptav63
17-Nov-2024, 01:39 PM

I am not able to access videos from second class and further. I have already completed first class

profile
@niteshguptav63
16-Nov-2024, 10:56 AM

When will I get my course?

profile
@admin79
17-Nov-2024, 01:29 PM

Now, Your query was resolved.

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?