What is the factory function in JQ?

1 votes
50 views
Ethan Karla asked 28-Jul-2021 in Web Application by Ethan Karla

What is the factory function in JQ?

1 Answer

1 votes
Ravi Vishwakarma answered 02-Aug-2021 by Ravi Vishwakarma

Each jQuery selector starts with this $() , this sign is called a factory function, this factory function is written before working on jQuery. Like selecting tag name, class, id and more.

Syntax:
$().function-name ()
Example :
<!DOCTYPE html> <html lang='en' xmlns='http://www.w3.org/1999/xhtml'> <head>     <meta charset='utf-8' />     <title></title>     <script src='https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js'></script>     <script type='text/javascript'>         $(document).ready(function () {             $('div').click(function () {                 $(this).css({'background-color':'red'});             });         });     </script>     <style>         body {             margin: 10px;             padding: 10px;         }         div {             background-color: cyan;             color: white;             text-align: center;             font-size:20px;             height:100px;             line-height:80px;         }     </style> </head> <body>     <div id='div1'>Click me for changing the background-color </div> </body> </html>

Output: 

What is the factory function in JQ?