jQuery test Exercise and Solution


To run the jQuery code we need jQuery library. You can add directly the library of jQuery from below URL

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

jQuery Excercise and Solution

<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <title>jQuery Solution</title> </head> <body> <!----------Question a-------------> <p> Write jQuery code to add class called "visited" to all visited links </p> <style> .visited{color: red;} </style> <a href="http://google.com">Google</a> <a href="https://darussalam.pk">DarusSalam</a> <script> $("a:visited").addClass('visited'); </script> <!----------Question b-------------> <p> Write jQuery to hide all &lt;p&gt; tags inside div </p> <div id='main'><p>some text...</p><p>some text...</p></div> <script> $('#main p').hide(); </script> <!-------------Question C----------------------> <p>Write jQuery code to add class "textfields" to all text fields to all text fields on a web page.</p> <style> .textfields{border: green 2px solid;} </style> <input type="text" placeholder="Enter Username"><br><br> <input type="password" placeholder="Enter Password"><br> <script> $('input').addClass('textfields'); </script> <!----------Question d-------------> <p> Hide all images on all Webpage </p> <img src="https://darussalam.pk/images/d-pub-logo.png"> <script> $('img').hide(); </script> </body> </html>
Chapter Next »