Advertisement
gitman3

Untitled

Apr 22nd, 2024
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.21 KB | None | 0 0
  1. <!-- 1. Write a jQuery code snippet to change the text of a <div> element with the ID "myDiv" to "Hello, world!" when a
  2. button with the ID "changeTextBtn" is clicked. -->
  3.  
  4. <!DOCTYPE html>
  5. <html lang="en">
  6.  
  7. <head>
  8. <meta charset="UTF-8">
  9. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  10. <script src="https://code.jquery.com/jquery-3.7.1.min.js"
  11. integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
  12. <title>Document</title>
  13. </head>
  14.  
  15. <body>
  16. <script>
  17. $(document).ready(function () {
  18. $('#changeTxtBtn').click(function () {
  19. $('p').text("Hello World");
  20. });
  21. });
  22. </script>
  23.  
  24.  
  25. <div id="myDiv">
  26. <p>This is my div</p><button id="changeTxtBtn">Change</button>
  27. </div>
  28.  
  29. </body>
  30.  
  31. </html>
  32.  
  33.  
  34.  
  35. <!-- 2. Create a jQuery script that toggles the visibility of a <div> element with the class "toggleDiv" when a button with
  36. the ID "toggleBtn" is clicked. -->
  37.  
  38. <!DOCTYPE html>
  39. <html lang="en">
  40.  
  41. <head>
  42. <meta charset="UTF-8">
  43. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  44. <script src="https://code.jquery.com/jquery-3.7.1.min.js"
  45. integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
  46. <title>Document</title>
  47. </head>
  48.  
  49. <body>
  50. <script>
  51. $(document).ready(function () {
  52. let flag = true;
  53. $('#toggleBtn').click(function () {
  54.  
  55. if (flag) {
  56. $('.toggleDiv').hide();
  57. flag = false;
  58. }
  59. else if (!flag) {
  60. $('.toggleDiv').show();
  61. flag = true;
  62. }
  63. });
  64. });
  65. </script>
  66. <div class="toggleDiv" style="height: 300px; width: 300px; background-color: red;"></div>
  67. <button id="toggleBtn">Toggle</button>
  68.  
  69. </body>
  70.  
  71. </html>
  72.  
  73.  
  74.  
  75.  
  76. <!-- 3. Develop a jQuery function to dynamically generate a list of <li> elements inside a <ul> with the ID "myList" based on
  77. an array of strings ["Apple", "Banana", "Orange"]. -->
  78. <!DOCTYPE html>
  79. <html lang="en">
  80.  
  81. <head>
  82. <meta charset="UTF-8">
  83. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  84. <script src="https://code.jquery.com/jquery-3.7.1.min.js"
  85. integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
  86. <title>Document</title>
  87. </head>
  88. <script>
  89. $(document).ready(function () {
  90. const arr = ["Apple", "Banana", "Orange"];
  91. let i = 0;
  92. $('#btn').click(function () {
  93. $('#myList').append("<li>" + arr[i] + "</li>");
  94. i++;
  95. if (i == arr.length) {
  96. $('#btn').hide();
  97. }
  98. });
  99.  
  100. });
  101.  
  102. </script>
  103.  
  104. <body>
  105. <ul id="myList">
  106.  
  107. </ul>
  108. <button id="btn">add</button>
  109. </body>
  110.  
  111. </html>
  112.  
  113.  
  114.  
  115. <!-- 5. Create a jQuery function to slide down a <div> element with the class "slideDownDiv" when hovering over a button with
  116. the class "hoverBtn". -->
  117.  
  118. <!DOCTYPE html>
  119. <html lang="en">
  120.  
  121. <head>
  122. <meta charset="UTF-8">
  123. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  124. <script src="https://code.jquery.com/jquery-3.7.1.min.js"
  125. integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
  126. <title>Document</title>
  127. </head>
  128.  
  129. <body>
  130. <script>
  131. $(document).ready(function () {
  132. var toggle = false;
  133. $("#hoverBtn").hover(function () {
  134. if (!toggle) {
  135.  
  136. $("#div2").animate({ top: '100px' });
  137. toggle = true;
  138. }
  139. else {
  140. $("#div2").animate({ top: '0px' });
  141. toggle = false;
  142. }
  143. });
  144.  
  145. });
  146. </script>
  147. <button id="hoverBtn">Slide</button>
  148. <div id="div2" style="background-color: green; height: 200px; width: 200px;position: relative;">
  149. <p>This is me dehradun</p>
  150. </div>
  151.  
  152. </body>
  153.  
  154. </html>
  155.  
  156.  
  157.  
  158.  
  159.  
  160. <!-- 6. Write jQuery code to animate the width of a <div> element with the ID "animateDiv" from 100px to 300px over a
  161. duration of 1 second. -->
  162.  
  163. <!DOCTYPE html>
  164. <html lang="en">
  165.  
  166. <head>
  167. <meta charset="UTF-8">
  168. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  169. <script src="https://code.jquery.com/jquery-3.7.1.min.js"
  170. integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
  171. <title>Document</title>
  172. </head>
  173.  
  174. <body>
  175. <script>
  176. $(document).ready(function () {
  177. $("#btn").click(function () {
  178. $("#animateDiv").animate({
  179. height: '300px',
  180. width: '300px'
  181. }, 3000);
  182. });
  183.  
  184. });
  185. </script>
  186. <div id="animateDiv" style="background-color: yellow; height: 100px; width: 100px; position: relative; ">
  187. <p>This is geu dehradun</p>
  188. </div>
  189. <div class="class">
  190.  
  191. <button id="btn">animate</button>
  192. </div>
  193.  
  194. </body>
  195.  
  196. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement