If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
जैसा कि हम जानते हैं कि jQuery में कोई भी statement या किसी DOM (Document Object Model) Element (such as <div>, <p>, <span> etc..) select करने के लिए $ या jQuery use करते हैं।
चूंकि jQuery की तरह ही और भी JavaScript Frameworks और Libraries हैं like Angular JS , Ember JS , Preact JS.
अब अगर jQuery की तरह ही दुसरे Frameworks और Libraries भी $ का use कर रहें होंगे तो jQuery में Error आ सकती है और page breach हो सकता है।
इसके लिए jQuery noConflict() method provide कराती है जिससे हम shortcut identifier $ की जगह custom identifier use कर सकते हैं।
jQuery में custom identifier का सबसे पहला तरीका है , jQuery(document).ready(); event handler में pass किये जाने वाले callback function में custom identifier pass कर सकते हैं।
File : jquery_noconflict.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery Making Custom Identifier</title>
<script src="jquery-3.5.1.js"></script>
</head>
<body>
<p>My Para</p>
<script type="text/javascript">
jQuery(document).ready(function(customIdnt) {
console.log(customIdnt('p'));
});
</script>
</body>
</html>
ऊपर दिए गए example में customIdnt एक custom identofier है , जिसकी help से <p> element को console में print कराया गया है , जहाँ पर <p> element की सभी valid properties और available methods को देख सकते हैं।
noConflict() method का use करके भी हम custom identifier बना सकते हैं।
See Example
File : jquery_noconflict.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery Making Custom Identifier</title>
<script src="jquery-3.5.1.js"></script>
</head>
<body>
<p>My Para</p>
<script type="text/javascript">
var jqIdnt = jQuery.noConflict();
jQuery(document).ready(function() {
console.log(jqIdnt('p'));
});
</script>
</body>
</htmll>
इस तरह से noConflict() method का use करके other library को आसानी से use कर सकते हैं , और Conflicts avoid कर सकते हैं।
Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.
Get connected with me. :) LinkedIn Twitter Instagram Facebook