-
-
Notifications
You must be signed in to change notification settings - Fork 157
Added new blog - DOM manipulation in JavaScript #2091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added new blog - DOM manipulation in JavaScript #2091
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job, @DharshiBalasubramaniyam! 🎉 Thank you for submitting your pull request to CodeHarborHub. We appreciate your contribution and enthusiasm! Our team will review it soon. If you have any questions or need further assistance, feel free to reach out. Thanks for contributing!
Here's the code health analysis summary for commits Analysis Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update your code for best practice
Using var
is not considered good practice. Instead, prioritize using const
for variables that won't be reassigned. For variables that need to be reassigned, especially in loops, use let
. Avoid using var
to follow modern JavaScript best practices.
|
||
```js | ||
// Get all <p> elements in the document | ||
var paragraphs = document.getElementsByTagName("p"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using var
is generally not recommended. Prioritize const
for variables that do not change. If you need to reassign a variable, use let
. Avoid var
as a matter of good practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, replace var
to const
var paragraphs = document.getElementsByTagName("p"); | ||
|
||
// Loop through and log the text content of each <p> element | ||
for (var i = 0; i < paragraphs.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var
to let
|
||
```js | ||
// Select the first <p> element in the document | ||
var firstParagraph = document.querySelector("p"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var
to const
var firstParagraph = document.querySelector("p"); | ||
|
||
// Select the element with id="main-title" | ||
var titleElement = document.querySelector("#main-title"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var
to const
var titleElement = document.querySelector("#main-title"); | ||
|
||
// Select the first element with class="intro" | ||
var introParagraph = document.querySelector(".intro"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var
to const
var introParagraph = document.querySelector(".intro"); | ||
|
||
// Select the first <p> element inside the <div> | ||
var paragraphInDiv = document.querySelector("div p"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var
to const
```js | ||
|
||
// Select all <p> elements in the document | ||
var paragraphs = document.querySelectorAll("p"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, replace var
to const
done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Related Issue
fixes #2017
Description
Added new blog.
Type of PR
Screenshots / Videos (if applicable)
[Attach any relevant screenshots or videos demonstrating the changes]
Checklist