How I build  DOM manipulation project  using HTML, CSS3, JavaScript

How I build DOM manipulation project using HTML, CSS3, JavaScript

Hi everyone,

Welcome to my blog. In this project, I will show you how to code your first DOM project.

In this project, we put the day in the week in the input and after clicking the Button based on the input DOM will be manipulated

class,weekend,.gif

LINK- class-weekend-boring-day.netlify.app

GitHub- github.com/shubhamsigdar1/Class-Weekend-Bor..

What is DOM?


When we do rendering/Painting on our HTML and CSS in a browser i.e. make some changes and as we refresh our webpage all those changes are gone i.e. we re-rendered or repainted our HTML and CSS files i.e. called DOM

How we can add behavior and interaction to DOM so that we can manipulate the DOM?


We use JavaScript to manipulate the DOM

Note:-When we manipulate the DOM, We do not manipulate with actual HTML, CSS file

How to get started?


1. Install VS Code code.visualstudio.com/download

2. Install the extension(open in browser) in Vs Code.

3. In your text editor, create a folder Daily Music Generator and then create three separate files i.e. HTML, CSS, and JavaScript. This makes your code more organized.

image.png

Let's Start working on projects


First, we start from HTML files, where you can link CSS and JavaScript files using the code below: image.png


Below is the HTML code

image.png

In the above HTML code,

1. Code to link your HTML with the CSS file and we write it inside the head tag

image.png

2. Code to link your HTML with the JavaScript file and we write it inside the body tag image.png

3. we write class = 'hidden' in the section tag. image.png By using class = ‘hidden’ then we can toggle that class on and off i.e. hide and show section.

Below is the CSS code

image.png image.png image.png

In the above CSS code,

1. To define toggle on and off to the class = 'hidden' we give property display: none;

image.png

2. To add an image in a section I always use this property for the img tag and Section in which we have to put the image I apply the property "overflow: hidden;"

image.png

Below is the JavaScript code

image.png

In the above JavaScript code,

1. We want that when we click the check button and then run the function(), For that, we write code

image.png

2. To grab input value in the DOM from the input tag, For that, we write code

image.png

3. How to create an image element in the DOM and after that insert it into the section?

  • Create an empty img element using document.createElement() method.
  • Then set its attributes like (src, height, width, alt, title, etc).
  • Finally, insert it into the document. image.png

4. Meaning of these three lines

image.png

When we grab input Tuesday and Thursday then it will toggle only the section which has id #imagesection1 and hide all the other two section