From 22dcc7acb69f85d23f3dfd5fc52414aa02529db1 Mon Sep 17 00:00:00 2001 From: Anas Ahmed Date: Wed, 5 Apr 2023 00:06:08 +0530 Subject: [PATCH 1/2] Added Javascript DOM cheatsheet --- CheatSheets/JavaScript DOM-Cheatsheet.md | 83 ++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 CheatSheets/JavaScript DOM-Cheatsheet.md diff --git a/CheatSheets/JavaScript DOM-Cheatsheet.md b/CheatSheets/JavaScript DOM-Cheatsheet.md new file mode 100644 index 0000000..26e42b8 --- /dev/null +++ b/CheatSheets/JavaScript DOM-Cheatsheet.md @@ -0,0 +1,83 @@ +# JavaScript DOM Cheatsheet + +### What is DOM? + +The Document Object Model (DOM) is a programming interface for HTML documents. It represents the page so that programs can change the document structure, style, and content. + +## DOM Methods to find HTML elements: + +### Get Element by Id + +Returns the element that has the ID attribute with the specified value. + +```jsx +let element = document.getElementById("myElement"); +``` + +### Get Elements By Class Name + +Returns a collection of all elements in the document with the specified class name. + +```jsx +let elements = document.getElementsByClassName("myClass"); +``` + +### Get Elements By Tag Name + +Returns a collection of all elements in the document with the specified tag name. + +```jsx +let elements = document.getElementsByTagName("p"); +``` + +### Query Selector All + +Returns all elements that matches a specified CSS selector(s) in the document + +```jsx +let elements = document.querySelectorAll(".myClass"); +``` + +### InnerHTML + +Gets or sets the HTML content within an element. + +```jsx +element.innerHTML = "

New HTML content

"; +``` + +### InnerText + +Gets or sets the text content within an element. + +```jsx +element.innerText = "New text content"; +``` + +### Add Class + +Adds one or more class names to an element. + +```jsx +element.classList.add("newClass"); +``` + +### Remove Class + +Removes one or more class names from an element. + +```jsx +element.classList.remove("oldClass"); +``` + +### Add Event Listener + +Attaches an event handler to the specified element. + +```jsx +const myButton = document.getElementById("myButton"); + +myButton.addEventListener("click", function() { + console.log("Button clicked!"); +}); +``` \ No newline at end of file From fdf33b1af47c015eed17f0b899efe9051f41cac6 Mon Sep 17 00:00:00 2001 From: Anas Ahmed Date: Wed, 5 Apr 2023 00:14:56 +0530 Subject: [PATCH 2/2] Added Youtube video link of Javascript DOM --- CheatSheets/JavaScript DOM-Cheatsheet.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CheatSheets/JavaScript DOM-Cheatsheet.md b/CheatSheets/JavaScript DOM-Cheatsheet.md index 26e42b8..b3bb9d0 100644 --- a/CheatSheets/JavaScript DOM-Cheatsheet.md +++ b/CheatSheets/JavaScript DOM-Cheatsheet.md @@ -80,4 +80,8 @@ const myButton = document.getElementById("myButton"); myButton.addEventListener("click", function() { console.log("Button clicked!"); }); -``` \ No newline at end of file +``` + +# Learn More about JavaScript DOM from here: + +https://youtu.be/85jzHRTVdsc \ No newline at end of file