Interview Questions




Most Essential And Frequently Asked Interview
Questions And Answer

JQuery

Q.How to select dropdown item based on value

Ans.:

JQuery | Select dropdown item based on the value

Change the selected option by value on the select box with jQuery is common nowadays. So let us have a select element with the list of the fruits, and we need to "select" one of its options based on one of its values. What we do is just use the “selected” selector of jQuery

Let’s say we have the following select element and we need to dynamically select the option with a value of "CS", which would be the Cherries.

<select id="mySelect">
<option value="">Please Select</option>
<option value="AS">Apples</option>
<option value="BS">Blueberries</option>
<option value="CS">Cherries</option>
<option value="DS">Dewberries</option>
<option value="ES">Eggfruits</option>
</select>

Now below script select "Cherries" in select dropdown

<script>
$("#myselect option[value='CS']").attr('selected', 'selected');
    
// Or just use...

$("#myselect").val('CS');
</script>

The complete code will...

<html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script>
        $("#myselect option[value='CS']").attr('selected', 'selected');
    
        // Or just use...

        $("#myselect").val('CS');
    </script>
    </head>
    <body>
        <select id="mySelect">
        <option value="">Please Select</option>
        <option value="AS">Apples</option>
        <option value="BS">Blueberries</option>
        <option value="CS">Cherries</option>
        <option value="DS">Dewberries</option>
        <option value="ES">Eggfruits</option>
        </select>
    </body>
</html>

 

Q.What is JQuery?

Ans.:

jQuery: 

jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript.

View Detials

Q.How to refresh a page with jquery?

Ans.:

Jquery | Location reload() Method | Refresh a page

The Location.reload() method reloads the current URL.

View Detials

Q.How to get html attribute's value in jquery?

Ans.:

Jquery | attr | Get HTML attribute's value

You can get the value of an attribute for the first element in the set of matched elements using the .attr() function.

View Detials

Q.Remove id attribute from an element using jquery

Ans.:

Jquery | Remove id attribute from an element

The removeAttr() function from jquery is used to removes one or more attributes from the selected elements.

$("div").removeAttr("id");
View Detials