jQuery Multiple choices


Total available count: 24
Subject - JavaScript Frameworks
Subsubject - jQuery

Which jQuery method should be used to deal with name conflicts?


 

 

 

 



A


Solution:-

jQuery noConflict alias:-
In the below example you can see that the $.noConflict() method is used with a custom alias name ‘jQueryAlias‘. This code will also give you the proper output.

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.2.1.js"></script>
<script>
jQueryAlias = $.noConflict();
jQueryAlias (document).ready(function(){
 jQueryAlias ("button").click(function(){
 jQueryAlias ("div").fadeToggle("slow"); // this is still working
});
});
</script>
<style>
.divBlock{
width: 200px;
height: 100px;

padding: 20px;
margin: 20px;
background-color: yellow;
}
</style>
</head>

<body>

<div class="divBlock"></div>
<button>Test</button>
</body>
</html>

jQuery uses the noConflict() method to avoid the conflict of using $ variable with other JavaScript variables. The above examples will give you an idea about the usage of the noConflict method in jQuery.




Next 5 multiple choice(s)

1

Which jQuery method is used to switch between adding/removing one or more classes (for CSS) from selected elements?

2

Look at the following selector: $("div p"). What does it select?

3

Is jQuery a W3C standard?

4

Look at the following selector: $("p#intro"). What does it select?

5

Which jQuery method is used to remove selected elements?

Comments