jQuery noConflict In Hindi

📔 : JQuery 🔗

जैसा कि हम जानते हैं कि 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

Copy Fullscreen Close Fullscreen Run
<!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 को देख सकते हैं।

jQuery noConflict() Method

noConflict() method का use करके भी हम custom identifier बना सकते हैं।

See Example

File : jquery_noconflict.html

Copy Fullscreen Close Fullscreen Run
<!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 कर सकते हैं।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers