aakash2310

Untitled

Jul 17th, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.12 KB | None | 0 0
  1. <!-- 1. Write appropriate HTML-JavaScript-jQuery code for the following requirements:
  2. a. Assign appropriate font size, font family and background color to the <p> tag
  3. using the style property.
  4. b. Use the above <p> tag in three places in a html document and set this common
  5. style property to above tag.
  6. c. Use the above code to style the tags in multiple pages by using common file. -->
  7.  
  8. <!DOCTYPE html>
  9. <html lang="en">
  10. <head>
  11. <meta charset="UTF-8">
  12. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  13. <title>Document</title>
  14. <script src="../jquery-3.7.1.min.js"></script>
  15. </head>
  16. <body>
  17. <p style="font-size: large; font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; background-color: red;">static p</p>
  18. <p>dynamic-1</p>
  19. <p>dynamic-2</p>
  20. <p>dynamic-3</p>
  21.  
  22.  
  23. <script>
  24. $('p').css({"font-size": "large","font-family": "'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif","background-color": "orange"})
  25. </script>
  26. </body>
  27. </html>
  28.  
  29. <!DOCTYPE html>
  30. <html lang="en">
  31. <head>
  32. <meta charset="UTF-8">
  33. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  34. <title>Document</title>
  35. <script src="../jquery-3.7.1.min.js"></script>
  36. </head>
  37. <body>
  38. <p>otherp-1</p>
  39. <p>otherp-2</p>
  40. <p>otherp-3</p>
  41.  
  42. <script src="./pStyle.js"></script>
  43.  
  44. </body>
  45. </html>
  46.  
  47.  
  48. $('p').css({"font-size": "large","font-family": "'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif","background-color": "orange"})
  49.  
  50.  
  51. <!-- 2. Write appropriate HTML-JavaScript-jQuery code for the following requirements:
  52. a. Create a button, on click of it, welcome message should be displayed on web
  53. page just besides the button.
  54. b. Create three input textboxes. On click of each input box, change its background
  55. color to yellow.
  56. c. Create two style properties and by default apply first one to a paragraph. On a
  57. button click, change the paragraph style to other style.
  58. d. On paragraph-click, toggle its style.
  59. e. Create one button and a textbox. On button-click, set its value to the text written
  60. in the text box. -->
  61.  
  62. <!DOCTYPE html>
  63. <html lang="en">
  64. <head>
  65. <meta charset="UTF-8">
  66. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  67. <title>Document</title>
  68. <script src="../jquery-3.7.1.min.js"></script>
  69.  
  70. </head>
  71. <body>
  72.  
  73. <div style="display: flex;" id="message">
  74. <button onclick="showMessage()">Click to Welcome message</button>
  75. </div>
  76.  
  77. <div>
  78. <input type="text" id="input1">
  79. <input type="text" id="input2">
  80. <input type="text" id="input3">
  81. <input type="text" id="input4">
  82. </div>
  83.  
  84. <div>
  85. <p id="p1">hello World!!!</p>
  86. <button onclick="changeStyle()">Change Style</button>
  87. </div>
  88.  
  89. <div>
  90. <p id="toggleStyle" style="background-color: bisque; color: brown;">on click Toggle Style</p>
  91. </div>
  92.  
  93. <div>
  94. <input type="text" name="txt" id="txt" >
  95. <button onclick="changeValue(this)">My name is Aakash!!</button>
  96. </div>
  97.  
  98.  
  99. <script>
  100. function showMessage()
  101. {
  102. $("#message").append("<p style='color:red;'>Welcome back Aakash!!!</p>")
  103. }
  104.  
  105. $("input").click((e)=>{
  106. // console.log(e);
  107. $(`#${e.target.id}`).css({"background-color":"yellow"})
  108. })
  109.  
  110. function changeStyle()
  111. {
  112. console.log("hello");
  113. $("#p1").css({"background-color":"yellow","color":"red"})
  114. }
  115.  
  116. let toggle=true;
  117. $("#toggleStyle").click((e)=>{
  118. if(toggle)
  119. $(`#${e.target.id}`).css({"background-color":"yellow","color":"blue"})
  120. else
  121. $(`#${e.target.id}`).css({"background-color":"bisque","color":"brown"})
  122. toggle=!toggle;
  123. })
  124.  
  125. function changeValue(e)
  126. {
  127. e.textContent=$("#txt").val()
  128. }
  129.  
  130. </script>
  131. </body>
  132. </html>
  133.  
  134. <!-- 3. Write appropriate HTML-JavaScript-jQuery code for the following requirements:
  135. a. When the document is ready, create a div tag (id: div1) to display display
  136. Welcome message.
  137. b. Create two div tags (id: div2 and div3). When mouse moves over the div1,
  138. assign green as background color to both div2 and div3. When mouse moves
  139. out the div1, resent background color to white.
  140. c. Display and hide a paragraph on click of two buttons btnShow and btnHide.
  141. d. Perform the above task 3-c using a single button. toggle(). -->
  142.  
  143. <!DOCTYPE html>
  144. <html lang="en">
  145.  
  146. <head>
  147. <meta charset="UTF-8">
  148. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  149. <title>Program-3</title>
  150. <script src="../jquery-3.7.1.min.js"></script>
  151. </head>
  152.  
  153. <body>
  154.  
  155. <div id="div2">Div-2</div>
  156. <div id="div3">Div-3</div>
  157.  
  158. <div>
  159. <button onclick="showPara()">Show!!</button>
  160. <button onclick="hidePara()">Hide!!</button>
  161. <button onclick="togglePara()">Toggle!!</button>
  162. <p id="hideShow">paragraph show !!!</p><br>
  163. </div>
  164.  
  165.  
  166.  
  167. <script>
  168. $(document).ready(() => {
  169. $(document.body).prepend("<div id='div1' style='width:650px;height:50px;border:2px solid black;'>Welcome message</div>")
  170.  
  171. $("#div1").mouseover(() => {
  172. $("#div2").css({ "background-color": "green" })
  173. $("#div3").css({ "background-color": "green" })
  174. })
  175.  
  176. $("#div1").mouseout(() => {
  177. $("#div2").css({ "background-color": "white" })
  178. $("#div3").css({ "background-color": "white" })
  179. })
  180.  
  181. })
  182.  
  183. let toggle = true;
  184. function showPara() {
  185. $("#hideShow").css({ "display": "block" })
  186. toggle=true;
  187. }
  188. function hidePara() {
  189. $("#hideShow").css({ "display": "none" })
  190. toggle=false;
  191. }
  192.  
  193. function togglePara() {
  194. if (toggle)
  195. $("#hideShow").css({ "display": "none" })
  196. else
  197. $("#hideShow").css({ "display": "block" })
  198. toggle = !toggle;
  199. }
  200.  
  201.  
  202. </script>
  203. </body>
  204.  
  205. </html>
  206.  
  207. <!-- 4. Write appropriate HTML-JavaScript-jQuery code for the following requirements:
  208. a. Create one textarea (id: ta1) and one button (id: showTextCount).
  209. On click of the button, display count of text available in ta1 on document.
  210. b. Create one textarea (id: ta2).
  211. Update text count as and when text is entered. Display the same on document.
  212. c. Restrict the max. number of characters to 10 in ta2. -->
  213.  
  214. <!DOCTYPE html>
  215. <html lang="en">
  216. <head>
  217. <meta charset="UTF-8">
  218. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  219. <title>program-4</title>
  220. <script src="../jquery-3.7.1.min.js"></script>
  221. </head>
  222. <body>
  223. <textarea name="txt" id="ta1" cols="30" rows="10"></textarea>
  224. <button onclick="countChr()">count characters!!</button>
  225. <p id="result" style="color: red;"></p>
  226.  
  227. <textarea name="txt" id="ta2" cols="30" rows="10" maxlength="10"></textarea>
  228. <p id="result2"></p>
  229. <h1 id="showText"></h1>
  230.  
  231.  
  232. <script>
  233. function countChr()
  234. {
  235. let txt=$("#ta1").val();
  236. $("#result").text(`total character is : ${txt.length}`)
  237. }
  238.  
  239. $("#ta2").keyup(()=>{
  240. console.log("hello");
  241. let txt=$("#ta2").val();
  242. $("#result2").text(`total character is : ${txt.length}`)
  243. $("#showText").text(`${txt}`)
  244.  
  245.  
  246. })
  247.  
  248. </script>
  249.  
  250. </body>
  251. </html>
  252.  
  253. <!-- 5. Write appropriate HTML-JavaScript-jQuery code for the following requirements:
  254. a. Create one style class with name ‘error’:-
  255. i. border color : red
  256. ii. background color : yellow.
  257. iii. Apply this class to a text box when the focus is moved out of it and if
  258. entered data is a negative number.
  259. b. Create two textboxes and one button with + on it. On click of the + button,
  260. display sum of the numbers entered in two textboxes. Also perform same
  261. functionality for subtract, multiply and divide buttons.
  262. c. The buttons in above code 5-b should remain in disable state until any one or
  263. both of the textboxes are vacant. -->
  264. <!DOCTYPE html>
  265. <html lang="en">
  266.  
  267. <head>
  268. <meta charset="UTF-8">
  269. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  270. <title>program-5</title>
  271. <style>
  272. .error {
  273. border: 2px solid red;
  274. background-color: yellow;
  275.  
  276. }
  277. </style>
  278. <script src="../jquery-3.7.1.min.js"></script>
  279. </head>
  280.  
  281. <body>
  282.  
  283. <div>
  284. <input type="number" id="number" placeholder="enter the number..">
  285. </div>
  286.  
  287. <script>
  288. $("#number").keyup(()=>{
  289. let val = Number($("#number").val());
  290. if (val < 0)
  291. $("#number").addClass("error");
  292. else
  293. $("#number").removeClass("error");
  294. })
  295. $("#number").(()=>{
  296. $("#number").addClass("error");
  297. })
  298. $("#number").focus(()=>{
  299. $("#number").removeClass("error");
  300. })
  301.  
  302. </script>
  303.  
  304. </body>
  305.  
  306. </html>
Advertisement
Add Comment
Please, Sign In to add comment