-
Notifications
You must be signed in to change notification settings - Fork 32
Durga dom manipulation js #538
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
|
|
||
| * { | ||
| margin: 0; | ||
| padding: 0; | ||
| box-sizing: border-box; | ||
| } | ||
|
|
||
| body { | ||
| font-family: Arial, sans-serif; | ||
| line-height: 1.6; | ||
| } | ||
|
|
||
| header { | ||
| background: #0d0a99; | ||
| color: #fff; | ||
| padding: 20px; | ||
| text-align: center; | ||
| } | ||
|
|
||
| nav ul { | ||
| list-style: none; | ||
| display: flex; | ||
| justify-content: center; | ||
| gap: 20px; | ||
| margin-top: 10px; | ||
| } | ||
|
|
||
| nav a { | ||
| color: #fff; | ||
| text-decoration: none; | ||
| } | ||
|
|
||
| main { | ||
| display: flex; | ||
| padding: 20px; | ||
| gap: 20px; | ||
| } | ||
|
|
||
| article { | ||
| flex: 3; | ||
| background: #2c13a8; | ||
| color: #fff; | ||
| padding: 20px; | ||
| border-radius: 8px; | ||
| } | ||
|
|
||
| aside { | ||
| flex: 1; | ||
| background: #4d119b; | ||
| color: #fff; | ||
| padding: 20px; | ||
| border-radius: 8px; | ||
| } | ||
|
|
||
| footer { | ||
| background: #3f12ba; | ||
| color: #fff; | ||
| text-align: center; | ||
| padding: 15px; | ||
| margin-top: 20px; | ||
| bottom: auto; | ||
| } | ||
|
|
||
| @media (max-width: 768px) { | ||
| main { | ||
| flex-direction: column; | ||
| flex:1; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>CSS Animation & Media Queries</title> | ||
| <style> | ||
| body { | ||
| font-family: Arial, sans-serif; | ||
| margin: 0; | ||
| padding: 0; | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| height: 100vh; | ||
| background: #f0f0f0; | ||
| } | ||
| .box { | ||
| width: 150px; | ||
| height: 150px; | ||
| background: #3498db; | ||
| border-radius: 10px; | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| color: white; | ||
| font-weight: bold; | ||
| animation: bounce 2s infinite; | ||
| } | ||
| @keyframes bounce { | ||
| 0%, 100% { | ||
| transform: translateY(0); | ||
| } | ||
| 50% { | ||
| transform: translateY(-50px); | ||
| } | ||
| } | ||
| @media (max-width: 768px) { | ||
| .box { | ||
| width: 120px; | ||
| height: 120px; | ||
| font-size: 14px; | ||
| background: #e67e22; | ||
| } | ||
| } | ||
|
|
||
| @media (max-width: 480px) { | ||
| .box { | ||
| width: 90px; | ||
| height: 90px; | ||
| font-size: 12px; | ||
| background: #2ecc71; | ||
| } | ||
| } | ||
| </style> | ||
|
Comment on lines
+7
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The CSS styles are currently inside a |
||
| </head> | ||
| <body> | ||
| <div class="box">Hello Guys..!</div> | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,56 @@ | ||||||
| <!DOCTYPE html> | ||||||
| <html lang="en"> | ||||||
| <head> | ||||||
| <meta charset="UTF-8"> | ||||||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||||||
| <title>DOM Manipulation - Assignment 1</title> | ||||||
| <link rel="stylesheet" href="style.css"> | ||||||
| </head> | ||||||
| <body> | ||||||
| <h2>Assignment 1: Accessing and Manipulating Elements</h2> | ||||||
|
|
||||||
| <table> | ||||||
| <tr> | ||||||
| <th>id</th> | ||||||
| <th>className</th> | ||||||
| <th>tag</th> | ||||||
| <th>name</th> | ||||||
| <th>attribute</th> | ||||||
| </tr> | ||||||
|
|
||||||
| <tr> | ||||||
| <td> | ||||||
| <p id="para1">Paragraph 1</p> | ||||||
| <p id="para2">Paragraph 2</p> | ||||||
| <button onclick="changeColorById()">Change Color</button> | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||
| </td> | ||||||
| <td> | ||||||
| <p class="group">Class Element 1</p> | ||||||
| <p class="group">Class Element 2</p> | ||||||
| <p class="group">Class Element 3</p> | ||||||
| <button onclick="toggleClassColor()">Toggle Background</button> | ||||||
| </td> | ||||||
| <td> | ||||||
| <span>Tag Span 1</span><br> | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||
| <span>Tag Span 2</span><br> | ||||||
| <span>Tag Span 3</span><br> | ||||||
| <button onclick="changeSpanText()">Change Text</button> | ||||||
| </td> | ||||||
| <td> | ||||||
| <input type="text" name="user1" value="Sai"><br> | ||||||
| <input type="text" name="user2" value="Durga"><br> | ||||||
| <input type="text" name="user3" value="Chitti"><br> | ||||||
| <button onclick="toggleDisable()">Toggle Disable</button> | ||||||
| </td> | ||||||
| <td> | ||||||
| <p data-info="custom1">Custom Attribute 1</p> | ||||||
| <p data-info="custom2">Custom Attribute 2</p> | ||||||
| <button onclick="addCustomAttribute()">Add Attribute</button> | ||||||
| </td> | ||||||
| </tr> | ||||||
| </table> | ||||||
| <div id="output"></div> | ||||||
|
|
||||||
| <script src="script.js"></script> | ||||||
| </body> | ||||||
| </html> | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,41 @@ | ||||||
|
|
||||||
| function changeColorById() { | ||||||
| const ids = ["para1", "para2"]; | ||||||
| let output = ""; | ||||||
| ids.forEach(id => { | ||||||
| const el = document.getElementById(id); | ||||||
| const randomColor = "#" + Math.floor(Math.random() * 16777215).toString(16); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The random color generation logic can produce invalid hex color codes.
Suggested change
|
||||||
| el.style.color = randomColor; | ||||||
| output += `Changed color of ${id} to ${randomColor}<br>`; | ||||||
| }); | ||||||
| printResult(output); | ||||||
| } | ||||||
| function toggleClassColor() { | ||||||
| const elements = document.getElementsByClassName("group"); | ||||||
| for (let el of elements) { | ||||||
| el.classList.toggle("highlight"); | ||||||
| } | ||||||
| printResult("Toggled background color of all elements with class 'group'"); | ||||||
| } | ||||||
| function changeSpanText() { | ||||||
| const spans = document.getElementsByTagName("span"); | ||||||
| for (let i = 0; i < spans.length; i++) { | ||||||
| spans[i].innerHTML = "Updated Span " + (i + 1); | ||||||
| } | ||||||
| printResult("Updated text content of all <span> elements."); | ||||||
| } | ||||||
| function toggleDisable() { | ||||||
| const inputs = document.querySelectorAll("input[name]"); | ||||||
| inputs.forEach(input => { | ||||||
| input.disabled = !input.disabled; | ||||||
| }); | ||||||
| printResult("Toggled 'disabled' attribute for all input elements with name attribute."); | ||||||
| } | ||||||
| function addCustomAttribute() { | ||||||
| const element = document.querySelector("[data-info='custom1']"); | ||||||
| element.setAttribute("data-added", "newValue"); | ||||||
| printResult("Added new attribute: data-added='newValue' to element with data-info='custom1'"); | ||||||
| } | ||||||
| function printResult(message) { | ||||||
| document.getElementById("output").innerHTML = message; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| body { | ||
| font-family: Arial, sans-serif; | ||
| margin: 20px; | ||
| } | ||
|
|
||
| table, th, td { | ||
| border: 1px solid black; | ||
| border-collapse: collapse; | ||
| padding: 10px; | ||
| text-align: center; | ||
| } | ||
|
|
||
| h2 { | ||
| color: #2a5d84; | ||
| } | ||
|
|
||
| .highlight { | ||
| background-color: lightblue; | ||
| } | ||
|
|
||
| #output { | ||
| margin-top: 20px; | ||
| padding: 10px; | ||
| border: 1px dashed #555; | ||
| background-color: #f5f5f5; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>Moving Shadow DOM Elements</title> | ||
| <link rel="stylesheet" href="style.css"> | ||
| </head> | ||
| <body> | ||
| <h2>Moving Table Rows inside Shadow DOM</h2> | ||
|
|
||
| <div id="shadowHost"></div> | ||
|
|
||
| <div class="controls"> | ||
| <button id="upBtn">Move Up</button> | ||
| <button id="downBtn">Move Down</button> | ||
| <button id="topBtn">Move Top</button> | ||
| <button id="bottomBtn">Move Bottom</button> | ||
| </div> | ||
|
|
||
| <script src="script.js"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,90 @@ | ||||||||||||||||||
|
|
||||||||||||||||||
| const shadowHost = document.getElementById("shadowHost"); | ||||||||||||||||||
| const shadowRoot = shadowHost.attachShadow({ mode: "open" }); | ||||||||||||||||||
| const shadowHTML = ` | ||||||||||||||||||
| <style> | ||||||||||||||||||
| table { | ||||||||||||||||||
| border-collapse: collapse; | ||||||||||||||||||
| width: 100%; | ||||||||||||||||||
| text-align: center; | ||||||||||||||||||
| font-family: Arial; | ||||||||||||||||||
| } | ||||||||||||||||||
| td, th { | ||||||||||||||||||
| border: 1px solid black; | ||||||||||||||||||
| padding: 8px; | ||||||||||||||||||
| } | ||||||||||||||||||
| button { | ||||||||||||||||||
| margin: 2px; | ||||||||||||||||||
| padding: 4px 6px; | ||||||||||||||||||
| } | ||||||||||||||||||
| tr.selected { | ||||||||||||||||||
| background-color: lightyellow; | ||||||||||||||||||
| } | ||||||||||||||||||
| </style> | ||||||||||||||||||
|
|
||||||||||||||||||
| <table> | ||||||||||||||||||
| <thead> | ||||||||||||||||||
| <tr><th>#</th><th>Item</th><th>Actions</th></tr> | ||||||||||||||||||
| </thead> | ||||||||||||||||||
| <tbody> | ||||||||||||||||||
| ${Array.from({ length: 10 }, (_, i) => ` | ||||||||||||||||||
| <tr> | ||||||||||||||||||
| <td>${i + 1}</td> | ||||||||||||||||||
| <td>Item ${i + 1}</td> | ||||||||||||||||||
| <td> | ||||||||||||||||||
| <button class="up">Up</button> | ||||||||||||||||||
| <button class="down">Down</button> | ||||||||||||||||||
| <button class="top">Top</button> | ||||||||||||||||||
| <button class="bottom">Bottom</button> | ||||||||||||||||||
| </td> | ||||||||||||||||||
| </tr> | ||||||||||||||||||
|
Comment on lines
+34
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The buttons (
Suggested change
|
||||||||||||||||||
| `).join("")} | ||||||||||||||||||
| </tbody> | ||||||||||||||||||
| </table> | ||||||||||||||||||
| `; | ||||||||||||||||||
|
|
||||||||||||||||||
| shadowRoot.innerHTML = shadowHTML; | ||||||||||||||||||
|
|
||||||||||||||||||
| const tbody = shadowRoot.querySelector("tbody"); | ||||||||||||||||||
| let selectedRow = null; | ||||||||||||||||||
| tbody.addEventListener("click", (e) => { | ||||||||||||||||||
| if (e.target.closest("tr")) { | ||||||||||||||||||
| if (selectedRow) selectedRow.classList.remove("selected"); | ||||||||||||||||||
| selectedRow = e.target.closest("tr"); | ||||||||||||||||||
| selectedRow.classList.add("selected"); | ||||||||||||||||||
| } | ||||||||||||||||||
| }); | ||||||||||||||||||
|
|
||||||||||||||||||
| function moveUp(row) { | ||||||||||||||||||
| const prev = row.previousElementSibling; | ||||||||||||||||||
| if (prev) tbody.insertBefore(row, prev); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| function moveDown(row) { | ||||||||||||||||||
| const next = row.nextElementSibling; | ||||||||||||||||||
| if (next) tbody.insertBefore(next, row); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| function moveTop(row) { | ||||||||||||||||||
| tbody.insertBefore(row, tbody.firstElementChild); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| function moveBottom(row) { | ||||||||||||||||||
| tbody.appendChild(row); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| document.getElementById("upBtn").addEventListener("click", () => { | ||||||||||||||||||
| if (selectedRow) moveUp(selectedRow); | ||||||||||||||||||
| }); | ||||||||||||||||||
|
|
||||||||||||||||||
| document.getElementById("downBtn").addEventListener("click", () => { | ||||||||||||||||||
| if (selectedRow) moveDown(selectedRow); | ||||||||||||||||||
| }); | ||||||||||||||||||
|
|
||||||||||||||||||
| document.getElementById("topBtn").addEventListener("click", () => { | ||||||||||||||||||
| if (selectedRow) moveTop(selectedRow); | ||||||||||||||||||
| }); | ||||||||||||||||||
|
|
||||||||||||||||||
| document.getElementById("bottomBtn").addEventListener("click", () => { | ||||||||||||||||||
| if (selectedRow) moveBottom(selectedRow); | ||||||||||||||||||
| }); | ||||||||||||||||||
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.
The
flex: 1property on themainelement within this media query is likely not having the intended effect.mainis a flex container, not a flex item in a layout whereflex: 1would be meaningful. If the goal is to make the children (article,aside) take up equal space when stacked, you should apply flex properties to them instead. Since they already haveflexproperties defined, this line is unnecessary and can be removed.