<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged jquery</title>
<link>https://coderlegion.com/tag/jquery</link>
<description>Powered by Question2Answer</description>
<item>
<title>How to get full path of uploaded file in html using JavaScript</title>
<link>https://coderlegion.com/13623/how-to-get-full-path-of-uploaded-file-in-html-using-javascript</link>
<description>&lt;p style=&quot;text-align: justify;&quot;&gt;We know java Script refers to a client side scripting language. In case we consider you
    are trying to get the users system folder path. Basically you can’t do this. It is barely allowed to fetch the
    directory structure or path.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://kodlogs.net/?qa=blob&amp;amp;qa_blobid=1477928991728469158&quot; alt=&quot;z13&quot; width=&quot;539&quot; height=&quot;359&quot;&gt;&lt;/p&gt;
&lt;h5 class=&quot;pk-title pk-toc-title pk-font-block&quot;&gt;Photo by &lt;a href=&quot;https://www.pexels.com/photo/people-standing-on-top-of-mountain-2114206/&quot; rel=&quot;nofollow&quot;&gt;Rachel Vine&lt;/a&gt;&lt;/h5&gt;
&lt;h5 class=&quot;pk-title pk-toc-title pk-font-block&quot;&gt;TABLE OF CONTENTS&lt;/h5&gt;
&lt;ol&gt;
    &lt;li&gt;&lt;a style=&quot;color: #02be8f;&quot; rel=&quot;nofollow&quot; href=&quot;#step01&quot;&gt;Step 01 - Absolute path of a file&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a style=&quot;color: #02be8f;&quot; rel=&quot;nofollow&quot; href=&quot;#step02&quot;&gt;Step 02 - JavaScript to get the full path of file:&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a style=&quot;color: #02be8f;&quot; rel=&quot;nofollow&quot; href=&quot;#step03&quot;&gt;Step 03 - Store the value of the JavaScript variable image Path in the MySQL database&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a style=&quot;color: #02be8f;&quot; rel=&quot;nofollow&quot; href=&quot;#Conclusion&quot;&gt;Conclusion&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 style=&quot;text-align: justify;font-size: 25px;&quot; id=&quot;step01&quot;&gt;Absolute path of a file:&lt;/h2&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;If you wish to get the absolute path of a file you can choose the jQuery attr() method.
    In addition, in the web page a file such as image, pdf, docs is display by giving its path to src attribute of an
    element. Now, you need to control that element’s id or class. After that usage the .attr() method to catch the src
    value.&lt;/p&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;Code:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;var absolutePath=$(&quot;elementId&quot;).attr(&quot;src&quot;);&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In case you are able to catch absolute path as:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/dir1/pdf/grapes.pdf&lt;/code&gt;&lt;/pre&gt;
&lt;p style=&quot;text-align: justify;&quot;&gt;Later on, you need to add the domain URL before of it because ‘/’ explains the root directory for the domain.&lt;/p&gt;
&lt;h3 style=&quot;text-align: justify;&quot; id=&quot;step02&quot;&gt;JavaScript to get the full path of file:&lt;/h3&gt;
&lt;div&gt;Try this code:&lt;/div&gt;
&lt;div&gt;
&lt;pre&gt;
&lt;code class=&quot;language-javascript&quot;&gt;
    &lt;input type=&quot;file&quot; name=&quot;file1&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;MAX_FILE_SIZE&quot; value=&quot;30000&quot;&gt;
&lt;/code&gt;
&lt;/pre&gt;
    &lt;p style=&quot;text-align: justify;&quot;&gt;Next step set this JavaScript function within the head tags. The forms on submit value set the function name as well.&lt;/p&gt;
&lt;pre&gt;
&lt;code class=&quot;language-javascript&quot;&gt;
    
    function getPath() {
        var inputName = document.getElementById('file1');
        var imgPath;

        imgPath = inputName.value;
        alert(imgPath);
    }
    
&lt;/code&gt;
&lt;/pre&gt;

&lt;pre&gt;
&lt;code class=&quot;language-javascript&quot;&gt;
    
    ...
    
&lt;/code&gt;
&lt;/pre&gt;

&lt;h3 id=&quot;step03&quot;&gt;Store the value of the JavaScript variable image Path in the MySQL database:&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;pre&gt;
&lt;code class=&quot;language-html&quot;&gt;
    &amp;lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&amp;gt;
    
    
    &lt;meta content=&quot;text/html; charset=iso-8859-1&quot;&gt;
    This is a test
    
    function getPath() {
    var Form = document.forms['frm_upload'];
    var inputName = Form.elements['file1'].value;

    var imgPath = inputName;
    Form.elements['file_src'].value = imgPath;
    }
    
    

    
    &quot; onSubmit=&quot;getPath();&quot;&amp;gt;
    &lt;input name=&quot;file1&quot; type=&quot;file&quot;&gt;&lt;br&gt;
    &lt;input name=&quot;file_src&quot; type=&quot;hidden&quot; value=&quot;&quot;&gt;
    &lt;input name=&quot;btn_submit&quot; type=&quot;submit&quot; value=&quot;show path&quot;&gt;
    
    &amp;lt;?php
        echo stripslashes($_POST[&quot;file_src&quot;]);
    ?&amp;gt;
    
    
&lt;/code&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&quot;Conclusion&quot; style=&quot;line-height: 2;&quot;&gt;&lt;span style=&quot;color: #000000;&quot;&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;p style=&quot;text-align: left;&quot;&gt;Hope it helped.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/13623/how-to-get-full-path-of-uploaded-file-in-html-using-javascript</guid>
<pubDate>Sun, 29 Mar 2026 01:52:58 +0000</pubDate>
</item>
<item>
<title>Typeerror: $(...).autocomplete is not a function</title>
<link>https://coderlegion.com/9703/typeerror-autocomplete-is-not-a-function</link>
<description>&lt;p&gt;Have you ever come across an error message that goes something like
&lt;strong&gt;&quot;Typeerror: $(...).autocomplete is not a function&quot;&lt;/strong&gt;?
It can be quite a head-scratcher, especially if you're new to coding.
But don't sweat it - we've all been there.
This error typically pops up when you're working with
&lt;strong&gt; jQuery UI&lt;/strong&gt;,and it indicates that the
&lt;strong&gt;autocomplete&lt;/strong&gt; method isn't being recognized or found.
This might be due to a variety of reasons, like a missing library or a loading sequence issue which can be solved by re-arranging the loading sequence correctly.
Let's dive into this error and find ways to fix it.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://logiclair.org/?qa=blob&amp;amp;qa_blobid=3286495429260705101&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h2&gt;What is jQuery UI?&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;jQuery UI&lt;/strong&gt; is a comprehensive set of components designed for user interface interactions, effects, widgets, and themes. It is built using the&lt;strong&gt; jQuery&lt;/strong&gt; JavaScript Library. It's all about making web development fast and easy. Whether you're building highly interactive web applications or just need to add a date picker to a form control, jQuery UI is the perfect choice. It provides a powerful platform that helps you to design a user-friendly and interactive web interface. Its rich set of features includes &lt;strong&gt;autocomplete&lt;/strong&gt;, drag and drop, modal functionality, and slider among others. Plus, it's compatible with a wide range of browsers, making your life as a developer a whole lot easier!&lt;/p&gt;
&lt;h2&gt;What causes that error to occur?&lt;/h2&gt;
&lt;p&gt;Firstly, this error may occur when the jQuery UI library isn't correctly linked or simply missing from your project. The autocomplete functionality is a part of the jQuery UI, not the basic jQuery library. Hence, if jQuery UI isn't correctly integrated, the autocomplete method won't be available, leading to this error.&lt;/p&gt;
&lt;p&gt;Secondly, the &lt;strong&gt;loading sequence&lt;/strong&gt; of your scripts also plays a significant role. The jQuery core library must be loaded before the jQuery UI library because jQuery UI is essentially an extension of the core jQuery library. If the jQuery UI script is loaded first, it won't find the jQuery object it needs to extend, and thus, you'll encounter the &quot;Typeerror: $(...).autocomplete is not a function&quot; error.&lt;/p&gt;
&lt;div class=&quot;div-green&quot;&gt;
&lt;span class=&quot;alert-header&quot;&gt;Tip&lt;/span&gt;
&lt;span class=&quot;alert-body&quot;&gt;When you see this error, it's basically the script's way of telling you, &quot;Hey, I can't find the autocomplete function to use here. Please check if you've linked all necessary libraries and the order they're loaded in.&lt;/span&gt;
&lt;/div&gt;
&lt;h2&gt;The scenario of producing that error&lt;/h2&gt;
&lt;p&gt;Let's say you have an &lt;strong&gt;input&lt;/strong&gt; element for vegetable names and you are using the autocomplete method from the jQuery UI, so when the user starts to enter characters, the input suggests names that include those characters.&lt;/p&gt;
&lt;p&gt;First, you will need to include the scripts for &lt;strong&gt;jQuery&lt;/strong&gt; and&lt;strong&gt; jQuery UI&lt;/strong&gt;, then include the &lt;strong&gt;input&lt;/strong&gt;, and lastly include another script element to use the &lt;strong&gt;autocomplete&lt;/strong&gt; method. So the code for example will be like this:&lt;/p&gt;
&lt;pre&gt;
&lt;code class=&quot;language-html&quot;&gt;&amp;lt;!DOCTYPE html&amp;gt;


&lt;meta&gt;
&lt;meta content=&quot;width=device-width, initial-scale=1&quot;&gt;
jQuery UI





&lt;label&gt;Vegetable Name&lt;/label&gt;
&lt;input id=&quot;vegetableName&quot; type=&quot;text&quot;&gt;


const vegetables = [&quot;Broccoli&quot;, &quot;Spinach&quot;, &quot;Kale&quot;, &quot;Carrots&quot;, &quot;Peas&quot;, &quot;Bell peppers&quot;, &quot;Sweet potatoes&quot;, &quot;Garlic&quot;, &quot;Onions&quot;, &quot;Beetroot&quot;];

$(function() {
$(&quot;#vegetableName&quot;).autocomplete({
source: vegetables
})
});


&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;All seems fine so far, but when you load this HTML document you will get our &quot;Typeerror: $(...).autocomplete is not a function&quot; error and that's because of the order of these two lines:&lt;/p&gt;
&lt;pre&gt;
&lt;code class=&quot;language-html&quot;&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;The solutions&lt;/h2&gt;
&lt;h3&gt;Solution 1: &lt;strong&gt;&lt;strong&gt;Load the libraries in the correct order&lt;/strong&gt;&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;The order in which you load your libraries matters. The jQuery UI components are built on the jQuery library, so the jQuery library like the parent. Therefore, your HTML script tags should first include the jQuery library ( the parent ) and then the jQuery UI ( the sibling). The scripts are loaded sequentially, so the order should be like:&lt;/p&gt;
&lt;pre&gt;
&lt;code class=&quot;language-html&quot;&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Solution 2:  &lt;strong&gt;&lt;strong&gt;Check for conflicts&lt;/strong&gt;&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;JavaScript libraries, other than jQuery, might use the &lt;strong&gt;&quot;$&quot;&lt;/strong&gt; variable, just like jQuery does. This can cause conflicts with jQuery. By using &lt;strong&gt;&quot;jQuery.noConflict()&quot;&lt;/strong&gt;, you hand back control of the &quot;$&quot; variable to whichever library first implemented it. After you do this, &quot;$&quot; will no longer represent &quot;jQuery&quot;: instead, you'll need to use the full word &quot;jQuery&quot; to call any jQuery functionality.&lt;/p&gt;
&lt;h3&gt;Solution 3: &lt;strong&gt;&lt;strong&gt;Re-initialize the widget&lt;/strong&gt;&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Sometimes, you might have all the scripts properly loaded and in the correct order, but the page itself doesn't load correctly, or some other script interferes with the initialization of the autocomplete widget. In such a case, re-initializing the widget after the page has fully loaded might help. You can do this by placing your autocomplete initialization code inside a &lt;strong&gt;&quot;$(document).ready()&quot;&lt;/strong&gt; function, which ensures that the entire page (DOM) is fully loaded before the script runs.&lt;/p&gt;
&lt;h3&gt;Solution 4: &lt;strong&gt;&lt;strong&gt;Check the jQuery version&lt;/strong&gt;&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;The jQuery Autocomplete function is a feature of jQuery UI, not the jQuery core library. Ensure that you're using a version of jQuery that supports the autocomplete function. For example, if you're using &lt;strong&gt;jQuery 1.3.2&lt;/strong&gt;, the autocomplete function may not work because it was introduced in &lt;strong&gt;jQuery UI 1.8&lt;/strong&gt;, which requires at least &lt;strong&gt;jQuery 1.4.2&lt;/strong&gt; to function correctly.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;In conclusion, troubleshooting &lt;strong&gt;jQuery's autocomplete&lt;/strong&gt; function might seem a little daunting at first, but with a systematic approach, you can resolve most issues easily. Remember to &lt;strong&gt;check the order of script loading&lt;/strong&gt;, &lt;strong&gt;look out for conflicts&lt;/strong&gt;, &lt;strong&gt;check the jQuery version&lt;/strong&gt;, and don't forget to &lt;strong&gt;re-initialize the widget&lt;/strong&gt; if needed. Keep these tips in your coding toolkit and you're sure to have a smoother journey navigating the world of jQuery. Happy coding, folks&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/9703/typeerror-autocomplete-is-not-a-function</guid>
<pubDate>Wed, 14 Jan 2026 12:41:10 +0000</pubDate>
</item>
<item>
<title>How to get radio button value in jquery</title>
<link>https://coderlegion.com/9700/how-to-get-radio-button-value-in-jquery</link>
<description>&lt;h2&gt;How to Get Radio Button Value in jQuery ?&lt;/h2&gt;
&lt;p&gt;Radio buttons are an &lt;strong&gt;input element &lt;/strong&gt;that allows users to select only one item from a list. When working with forms and user interactions, &lt;strong&gt;retrieving the selected value&lt;/strong&gt; of a radio button is a regular operation. This article will show you how to&lt;strong&gt; use jQuery&lt;/strong&gt; &lt;strong&gt;to get the value &lt;/strong&gt;of a radio button.&lt;/p&gt;
&lt;div id=&quot;toc-div&quot;&gt;
&lt;h4&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;&lt;strong&gt;Table of Contents: &lt;a id=&quot;toc-toogle&quot; class=&quot;open&quot;&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/h4&gt;
&lt;div id=&quot;toc-list&quot;&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;#what&quot; rel=&quot;nofollow&quot;&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;What does it mean by Retrieving Radio Buttons Value in jQuery?&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#why&quot; rel=&quot;nofollow&quot;&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;Getting the Values of Radio Buttons&lt;/span&gt;&lt;/a&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;#why1&quot; rel=&quot;nofollow&quot;&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;Getting Radio Selected Value Using Class&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#why2&quot; rel=&quot;nofollow&quot;&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;Getting Radio Selected Value Using Attribute Name with Value&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#why3&quot; rel=&quot;nofollow&quot;&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;Getting Radio Selected Value Using Attribute Type and Value&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#when&quot; rel=&quot;nofollow&quot;&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;Some Alternative Approaches&lt;/span&gt;&lt;/a&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;#when3&quot; rel=&quot;nofollow&quot;&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;Using the .change() Event&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#when4&quot; rel=&quot;nofollow&quot;&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;Using the .click() Event&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;&lt;a href=&quot;#con&quot; rel=&quot;nofollow&quot;&gt;References&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;section&gt;&lt;a id=&quot;what&quot; class=&quot;custom_anchor&quot;&gt;&lt;/a&gt;&lt;/section&gt;
&lt;section&gt;
&lt;h2&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;&lt;strong&gt;What does it mean by Retrieving Radio Buttons Value in jQuery?&lt;/strong&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;Retrieving radio button values with jQuery refers to the &lt;strong&gt;process of finding out and gathering&lt;/strong&gt; an option of choice from a group of radio buttons in a web form &lt;strong&gt;using the jQuery library&lt;/strong&gt;, a useful tool for simplifying JavaScript code. Radio buttons are typically used when users must choose a single option from a list of options.&lt;br&gt;Developers may use jQuery to write code that &lt;strong&gt;monitors for user input&lt;/strong&gt; with these radio buttons. When a user clicks a radio button to make a selection, jQuery &lt;strong&gt;assists in determining&lt;/strong&gt; which button was pressed and &lt;strong&gt;retrieving the value associated&lt;/strong&gt; with it. This value can be used to process form submissions, update web content, or trigger particular actions based on the user's selection.&lt;/p&gt;
&lt;h3&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;Syntax for jQuery code&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;$(selector).action();&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;$:&lt;/strong&gt; Represents the jQuery library symbol, providing access to its functions.&lt;br&gt;&lt;strong&gt;selector:&lt;/strong&gt; Identifies the HTML element(s) to be targeted, similar to how CSS selectors work.&lt;br&gt;&lt;strong&gt;action(): &lt;/strong&gt;Denotes the specific jQuery action to be performed on the selected element(s), such as modifying content, applying styles, or handling events.&lt;/p&gt;
&lt;/section&gt;
&lt;section&gt;&lt;a id=&quot;why&quot; class=&quot;custom_anchor&quot;&gt;&lt;/a&gt;&lt;/section&gt;
&lt;section&gt;
&lt;h2&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;&lt;strong&gt;Getting the Values of Radio Buttons:&lt;/strong&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;To get the value of a radio button using jQuery, you can use the following methods:&lt;/p&gt;
&lt;section&gt;&lt;a id=&quot;why1&quot; class=&quot;custom_anchor&quot;&gt;&lt;/a&gt;&lt;/section&gt;
&lt;h3&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;1. Getting Radio Selected Value Using Class&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;In this method, you'll give the radio buttons a class and then use that class to target the selected radio button.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;HTML:&lt;br&gt;&lt;/strong&gt;Add the class=&quot;fruit-radio&quot; attribute to each radio button.
&lt;pre&gt;&lt;code&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;&lt;input type=&quot;radio&quot; name=&quot;fruit&quot; class=&quot;fruit-radio&quot; value=&quot;apple&quot;&gt; Apple&lt;br&gt;
&lt;input type=&quot;radio&quot; name=&quot;fruit&quot; class=&quot;fruit-radio&quot; value=&quot;banana&quot;&gt; Banana&lt;br&gt;
&lt;input type=&quot;radio&quot; name=&quot;fruit&quot; class=&quot;fruit-radio&quot; value=&quot;orange&quot;&gt; Orange&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;jQuery:&lt;/strong&gt;&lt;br&gt;Then use the class selector .fruit-radio in the script.&lt;br&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;$(document).ready(function() {&lt;br&gt;
    $(&quot;.fruit-radio&quot;).on(&quot;click&quot;, function() {&lt;br&gt;
        var selectedFruit = $(&quot;.fruit-radio:checked&quot;).val();&lt;br&gt;
        console.log(&quot;Selected fruit using class: &quot; + selectedFruit);&lt;br&gt;
    });&lt;br&gt;
});&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Each radio button in the group has the class &quot;fruit-radio&quot; applied to it.&lt;/li&gt;
&lt;li&gt;The&lt;strong&gt;.fruit-radio:checked selector&lt;/strong&gt; is used to target the radio button with the class &quot;fruit-radio&quot; that is presently checked.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;.val() method&lt;/strong&gt; retrieves the value of the selected radio button.&lt;br&gt;&lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;
This is how the output is shown on the webpage:       
&lt;p&gt;&lt;a title=&quot;&quot;&gt;&lt;img src=&quot;https://logiclair.org/?qa=blob&amp;amp;qa_blobid=10257173123996631164&quot; alt=&quot;&quot; width=&quot;600&quot; height=&quot;200&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;section&gt;&lt;a id=&quot;why2&quot; class=&quot;custom_anchor&quot;&gt;&lt;/a&gt;&lt;/section&gt;
&lt;h3&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;2. Getting Radio Selected Value Using Attribute Name with Value&lt;br&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;In this approach, you'll target the radio buttons using the [name=&quot;fruit&quot;] &lt;strong&gt;attribute selector&lt;/strong&gt; and choose the checked one with &lt;strong&gt;:checked&lt;/strong&gt;.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;HTML:&lt;/strong&gt; &lt;br&gt;Add the name=&quot;fruit&quot; attribute to each radio button.
&lt;pre&gt;&lt;code&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;&lt;input type=&quot;radio&quot; name=&quot;fruit&quot; class=&quot;fruit-radio&quot; value=&quot;apple&quot;&gt; Apple&lt;br&gt;
&lt;input type=&quot;radio&quot; name=&quot;fruit&quot; class=&quot;fruit-radio&quot; value=&quot;banana&quot;&gt; Banana&lt;br&gt;
&lt;input type=&quot;radio&quot; name=&quot;fruit&quot; class=&quot;fruit-radio&quot; value=&quot;orange&quot;&gt; Orange&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;jQuery:&lt;/strong&gt;&lt;br&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;$(document).ready(function() {&lt;/code&gt; Ensures the code executes after the document is fully loaded.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;$(&quot;[name='fruit']&quot;).on(&quot;click&quot;, function() {&lt;/code&gt; Sets up a click event listener for the radio buttons with the name attribute set to &quot;fruit&quot;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;var selectedFruit = $(&quot;[name='fruit']:checked&quot;).val();&lt;/code&gt; Retrieves the value of the clicked radio button that is currently checked (selected).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;console.log(&quot;Selected fruit: &quot; + selectedFruit);&lt;/code&gt; Logs the selected fruit value to the console.&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;$(document).ready(function() {&lt;br&gt;
    $(&quot;[name='fruit']&quot;).on(&quot;click&quot;, function() {&lt;br&gt;
        var selectedFruit = $(&quot;[name='fruit']:checked&quot;).val();&lt;br&gt;
        console.log(&quot;Selected fruit using attribute name with value: &quot; + selectedFruit);&lt;br&gt;
    });&lt;br&gt;
});&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;The attribute selector [name=&quot;fruit&quot;] targets all elements with the attribute name set to &quot;fruit&quot;.&lt;/li&gt;
&lt;li&gt;The&lt;strong&gt; :checked selecto&lt;/strong&gt;r narrows down the selection to the radio button that is currently checked.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;.val() &lt;/strong&gt;method retrieves the value of the selected radio button.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
&lt;div class=&quot;div-green&quot;&gt;&lt;span class=&quot;alert-header&quot;&gt;Tip&lt;/span&gt; If you're working with more complex forms, consider using labels and CSS classes to make your code more organized and readable.&lt;/div&gt;
&lt;section&gt;&lt;a id=&quot;why3&quot; class=&quot;custom_anchor&quot;&gt;&lt;/a&gt;
&lt;h3&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;3. &lt;strong&gt;Getting Radio Selected Value Using Attribute Type and Value&lt;/strong&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;In this method, you'll use the [type=&quot;radio&quot;] attribute selector to target the radio buttons and :checked to select the checked one.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;HTML:&lt;br&gt;&lt;/strong&gt;Add the type=&quot;radio&quot; attribute to each radio button.
&lt;pre&gt;&lt;code&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;&lt;input type=&quot;radio&quot; name=&quot;fruit&quot; class=&quot;fruit-radio&quot; value=&quot;apple&quot;&gt; Apple&lt;br&gt;
&lt;input type=&quot;radio&quot; name=&quot;fruit&quot; class=&quot;fruit-radio&quot; value=&quot;banana&quot;&gt; Banana&lt;br&gt;
&lt;input type=&quot;radio&quot; name=&quot;fruit&quot; class=&quot;fruit-radio&quot; value=&quot;orange&quot;&gt; Orange&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;jQuery: &lt;/strong&gt;&lt;br&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;$(document).ready(function() {&lt;br&gt;
    $(&quot;[type='radio']&quot;).on(&quot;click&quot;, function() {&lt;br&gt;
        var selectedFruit = $(&quot;[type='radio']:checked&quot;).val();&lt;br&gt;
        console.log(&quot;Selected fruit using attribute type &amp;amp; value: &quot; + selectedFruit);&lt;br&gt;
    });&lt;br&gt;
});&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;The attribute selector [type=&quot;radio&quot;] targets all radio button elements on the page.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;:checked selector&lt;/strong&gt; filters the selection to the radio button that is currently checked.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;.val() method&lt;/strong&gt; retrieves the value of the selected radio button.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In each of the three methods, the code &lt;strong&gt;listens for a click event&lt;/strong&gt; on the radio buttons with the name &quot;fruit.&quot; When a radio button is pressed, the value of the &lt;strong&gt;selected fruit is obtained&lt;/strong&gt; using the proper process. The output is logged to the console, indicating the method's chosen fruit.&lt;br&gt;Using these three approaches, you may pick the way that best matches your coding style and project needs while still accomplishing the same purpose of getting the selected radio button value.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class=&quot;div-pink&quot;&gt;&lt;span class=&quot;alert-header&quot;&gt;Caution&lt;/span&gt; Ensure that your radio buttons have unique values within the same group to avoid confusion when retrieving values using jQuery.&lt;span class=&quot;alert-body&quot;&gt;&lt;br&gt;&lt;/span&gt;&lt;/div&gt;
&lt;section&gt;&lt;a class=&quot;custom_anchor&quot;&gt;&lt;/a&gt;&lt;/section&gt;
&lt;h2&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;&lt;strong&gt;Some Alternative Approches&lt;/strong&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;  There are some alternative approaches for capturing the selected value of radio buttons using jQuery:&lt;/p&gt;
&lt;section&gt;&lt;a id=&quot;when2&quot; class=&quot;custom_anchor&quot;&gt;&lt;/a&gt;&lt;/section&gt;
&lt;h3&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;&lt;strong&gt;1. Using the .change() Event&lt;/strong&gt;&lt;/span&gt;&lt;/h3&gt;
The &lt;code&gt;'.change()'&lt;/code&gt; event is triggered when the value of an input element changes, typically when a user interacts with it. It is specifically designed for capturing changes in input elements, making it an ideal choice for radio buttons.&lt;br&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;$(document).ready(function() {&lt;br&gt;
    $(&quot;.fruit-radio&quot;).on(&quot;change&quot;, function() {&lt;br&gt;
        var selectedFruit = $(&quot;.fruit-radio:checked&quot;).val();&lt;br&gt;
        console.log(&quot;Selected fruit using .change() event: &quot; + selectedFruit);&lt;br&gt;
    });&lt;br&gt;});&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;section&gt;&lt;a class=&quot;custom_anchor&quot;&gt;&lt;/a&gt;&lt;/section&gt;
&lt;h3&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;&lt;strong&gt;2. Using the .click() Event&lt;br&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;The &lt;strong&gt;.click() &lt;/strong&gt;event is triggered when an element is clicked. It's a common way to handle user interactions.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;$(document).ready(function() {&lt;br&gt;
    $(&quot;.fruit-radio&quot;).click(function() {&lt;br&gt;
        var selectedFruit = $(&quot;.fruit-radio:checked&quot;).val();&lt;br&gt;
        console.log(&quot;Selected fruit using class: &quot; + selectedFruit);&lt;br&gt;
    });&lt;br&gt;
});&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, for radio buttons, using the &lt;code&gt;.click()&lt;/code&gt; event might not be the most optimal choice, as it won't cover all scenarios, such as keyboard navigation. &lt;br&gt;&lt;br&gt;In simple words, this article will explain to you how to use jQuery to understand and capture your radio button selections. Websites get smarter and more engaging as a result of this.&lt;/p&gt;
&lt;/section&gt;
&lt;section&gt;&lt;a id=&quot;ref&quot; class=&quot;custom_anchor&quot;&gt;&lt;/a&gt;
&lt;h2&gt;&lt;span style=&quot;font-family: arial,helvetica,sans-serif;&quot;&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;Here are some reference links related to jQuery:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;jQuery Official Website&lt;br&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://jquery.com/&quot;&gt;https://jquery.com/&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;jQuery Attributes&lt;br&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://api.jquery.com/category/attributes/&quot;&gt; https://api.jquery.com/category/attributes/&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/9700/how-to-get-radio-button-value-in-jquery</guid>
<pubDate>Wed, 14 Jan 2026 12:36:24 +0000</pubDate>
</item>
<item>
<title>How to solve this problem &quot;Uncaught TypeError: $(...).datetimepicker is not a function&quot;</title>
<link>https://coderlegion.com/9698/how-to-solve-this-problem-uncaught-typeerror-datetimepicker-is-not-a-function</link>
<description>&lt;h1&gt;How to solve this problem &lt;i&gt;&quot;Uncaught TypeError: $(...).datetimepicker is not a function&quot;&lt;/i&gt;.&lt;/h1&gt;
&lt;p&gt;When we use the datetimepicker from &lt;a rel=&quot;nofollow&quot; href=&quot;http://eonasdan.github.io/bootstrap-datetimepicker/&quot;&gt;http://eonasdan.github.io/bootstrap-datetimepicker/&lt;/a&gt; , we often find the below error.&lt;br&gt;
&lt;strong&gt;&quot;Uncaught TypeError: $(...).datetimepicker is not a function&quot;&lt;/strong&gt;&lt;br&gt;
The reason of this error is the mistake of importing the datepicker plugin or formatting. We can fix it very easily. From now I’ll explain about it.&lt;/p&gt;
&lt;h2&gt;2. What is the problem&lt;/h2&gt;
&lt;p&gt;The datetimepicker is a jQuery plugin that provides a user-friendly way to select dates and times in web applications. It enhances the standard HTML input fields for date and time by adding a calendar and time picker functionality.&lt;br&gt;
With the datetimepicker plugin, users can easily select dates from a calendar and choose the time using a dropdown or a spinner. It offers various customization options, such as date and time format, minimum and maximum date limits, localization, and more.&lt;br&gt;
The plugin is commonly used in web forms, booking systems, event management applications, and any other scenario where date and time selection is required.&lt;br&gt;
The problem raised here is that errors occur in the process of using datetimepicker.&lt;br&gt;
&quot;Uncaught TypeError: $(...).datetimepicker is not a function&quot;&lt;br&gt;
&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=8291487432352604654&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h2&gt;3. What is the cause of the problem&lt;/h2&gt;
&lt;p&gt;The error message &quot;$(...).datetimepicker is not a function,&quot; typically occurs when the jQuery datetimepicker plugin is not properly loaded or initialized.&lt;/p&gt;
&lt;h2&gt;4. How did you reach this problem&lt;/h2&gt;
&lt;p&gt;There are several ways you can encounter the error message &quot;$(...).datetimepicker is not a function.&quot; Here are a few common scenarios:&lt;br&gt;
&lt;/p&gt;&lt;h3&gt;Missing or incorrect script inclusion:&lt;/h3&gt; If you haven't included the necessary JavaScript files for the datetimepicker plugin or if the file paths are incorrect, the plugin won't be loaded properly. Make sure you have included the jQuery library and the datetimepicker plugin script in your HTML file, and verify that the file paths are accurate.&lt;br&gt;
&lt;h3&gt;Script loading order:&lt;/h3&gt; The datetimepicker plugin relies on the jQuery library, so it needs to be loaded after jQuery. If you have included the datetimepicker script before jQuery, it can result in the error. Ensure that you have included the jQuery library before the datetimepicker plugin script.&lt;br&gt;
&lt;h3&gt;Conflicts with other libraries or plugins: &lt;/h3&gt; If there are conflicts between the datetimepicker plugin and other JavaScript libraries or plugins you are using, it can cause the error. Conflicts occur when multiple libraries define the same function name. To avoid conflicts, you can try using the jQuery.noConflict() method or check if there are any conflicting scripts in your code.&lt;br&gt;
&lt;h3&gt;Incorrect initialization: &lt;/h3&gt; If you haven't properly initialized the datetimepicker plugin on the desired element(s), you may encounter this error. Make sure you are calling the .datetimepicker() function on the appropriate element(s) in your JavaScript code.&lt;br&gt;
By reviewing these potential causes and troubleshooting steps, you should be able to identify and resolve the issue with the datetimepicker plugin.
&lt;h2&gt;5. How to solve $(...).datetimepicker is not a function issue?&lt;/h2&gt;
&lt;p&gt;Here are a few steps you can take to troubleshoot and resolve the issue:&lt;br&gt;
&lt;/p&gt;&lt;h3&gt;Make sure you have included the necessary dependencies: &lt;/h3&gt;Ensure that you have included the jQuery library and the datetimepicker plugin in your HTML file. You can do this by adding the following script tags to your HTML file:
&lt;pre&gt;&lt;code&gt;&amp;lt;script src=&quot;https://code.jquery.com/jquery-3.6.0.min.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src=&quot;path/to/datetimepicker.js&quot;&amp;gt;&amp;lt;/script&amp;gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Replace &quot;path/to/datetimepicker.js&quot; with the actual path to the datetimepicker plugin file on your server.&lt;br&gt;
&lt;/p&gt;&lt;h3&gt;Check the order of script inclusion: &lt;/h3&gt;Ensure that you have included the jQuery library before the datetimepicker plugin. The datetimepicker plugin relies on jQuery, so it needs to be loaded after jQuery.&lt;br&gt;
Verify the plugin initialization: After including the necessary scripts, make sure you are initializing the datetimepicker plugin correctly. You can do this by calling the .datetimepicker() function on the appropriate element(s) in your JavaScript code. For example:
&lt;pre&gt;&lt;code&gt;$(document).ready(function() {
     $('#datetimepicker').datetimepicker();
 });
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Replace #datetimepicker with the ID or class of the element you want to attach the datetimepicker to.&lt;br&gt;
&lt;/p&gt;&lt;h3&gt;Check for conflicts: &lt;/h3&gt;Ensure that there are no conflicts with other JavaScript libraries or plugins you might be using. Conflicts can occur if multiple libraries define the same function name. You can try using the jQuery.noConflict() method to avoid conflicts.&lt;br&gt;
If you've followed these steps and the issue persists, please provide more details about your code and any error messages you're receiving, so I can assist you further.
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/9698/how-to-solve-this-problem-uncaught-typeerror-datetimepicker-is-not-a-function</guid>
<pubDate>Wed, 14 Jan 2026 12:32:14 +0000</pubDate>
</item>
<item>
<title>Why I'm Still Using jQuery in 2025 (Never gonna give you up)</title>
<link>https://coderlegion.com/7069/why-im-still-using-jquery-in-2025-never-gonna-give-you-up</link>
<description>&lt;p&gt;While grinding through the monumental JuggleBee upgrade, one of the recurring debates was: what do we modernize, and what do we leave the heck alone? Plenty got a shiny new coat of paint (see my earlier posts for all the juicy details), but one area I deliberately left untouched was the frontend JavaScript. These days, jQuery is seen as a relic of a bygone era — a noble steed well past its sell-by date. Hotwire now ships as the Rails 8 default, and heavyweight contenders like React and Vue have taken over the frontend spotlight.&lt;/p&gt;
&lt;h3 id=&quot;why-i-kept-it&quot;&gt;Why I Kept It&lt;/h3&gt;
&lt;p&gt;So why didn’t I replace it with Hotwire or Stimulus when doing the big Rails 8 overhaul?&lt;/p&gt;
&lt;p&gt;Because honestly... it still &lt;em&gt;slaps&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Sure, jQuery has fallen out of favour, and yes, I could’ve followed the modern path. But here’s the reality:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;It still works. Flawlessly.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The architecture is solid.&lt;/strong&gt; It keeps behaviour modular and scoped. No random scripts firing across unrelated pages.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;It’s expressive and readable.&lt;/strong&gt; You can look at the markup and know exactly which components will be applied.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rewriting it would’ve cost me weeks&lt;/strong&gt; — and yielded very little gain for the effort.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It’s easy to chase shiny new frameworks. But this setup? It’s already solved the very problems frameworks like Stimulus are trying to address — just in our own way, before they existed.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&quot;Technical debt isn't defined by age. It's defined by pain.&quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This jQuery-based framework causes me &lt;strong&gt;zero&lt;/strong&gt; pain. It’s clean, consistent, and extendable. And I’m not paying a complexity tax for keeping it around.&lt;/p&gt;
&lt;h3 id=&quot;a-beautiful-framework&quot;&gt;A Beautiful Framework&lt;/h3&gt;
&lt;p&gt;Back in the yonder years, when development on JuggleBee first commenced, jQuery was king. &quot;Write less, do more&quot; as the slogan proudly declared. These were the days before Turbo, pre-SPAs, when frameworks like React were still internal tools being tinkered on at Facebook. Even then, I liked my code clean, purposeful, and targeted. Every function should do its job — and only its job — exactly where it’s meant to. The typical jQuery spaghetti of the time grated on me.&lt;/p&gt;
&lt;p&gt;Take this scenario: I’ve got a lovely &lt;code&gt;Select2&lt;/code&gt; dropdown on the listings page to filter by category. All good. But why is that whole library still being pulled in and initialized on the About Us page, which has no dropdowns in sight? This was a symptom of how jQuery scripts were commonly written — everything ran everywhere. I wanted modularity, not mayhem. And so, the “Behaviour Framework” was born.&lt;/p&gt;
&lt;p&gt;So what exactly did we build?&lt;/p&gt;
&lt;p&gt;In essence, it's a lightweight, declarative behaviour system — think of it like a primitive version of Stimulus or Alpine. Components declare themselves in the markup, and a central engine takes care of the wiring when the DOM loads. This means zero manual JS in our views, and zero unnecessary script execution across unrelated pages.&lt;/p&gt;
&lt;p&gt;Let me show you how it works...&lt;/p&gt;
&lt;p&gt;At the heart of it all is the &lt;code&gt;Behaviour&lt;/code&gt; class. Its role is simple but powerful: register UI components and apply them only when needed — and only on the elements that require them. Here's a high-level look at how it works under the hood:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;// Note: classes didnt exist so the &quot;Class&quot; we're calling below is a custom implementation
Framework.Behaviour = new Class({
  filters: {},
  addFilter:function(name, instantiator){
    this.filters[name] = instantiator;
  },
  addFilters:function(filters){
    for (const filter in filters){
      this.addFilter(filter, filters[filter]);
    }
  },
  apply:function(wrapper){
    this._scan(wrapper, $.proxy(this._apply, this));
  },
  unapply:function(wrapper){
    this._scan(wrapper, function(target, behaviourClassName){
      var behaviourResult = target.data('getBehaviourResult')(behaviourClassName);
      if (typeof behaviourResult.deinit === 'function'){
        behaviourResult.deinit();
      }
    });
  },
  // rest of the implentation ...
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This allows us to define small, focused components — like a date picker — in total isolation. No global bleed. No script soup. Just self-contained behaviour.&lt;/p&gt;
&lt;p&gt;One of the earliest components we wrote using this system was actually said date picker. At the time, we were using Bootstrap and jQuery UI plugins — each with their own quirks. So we wrapped them up into their own isolated modules, making them easier to configure and reuse across different forms, pages, and even admin views.&lt;/p&gt;
&lt;p&gt;Here’s what the class for that looked like:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;Component.DatePicker = new Class({
    options: {
        startDate: '04/07/2015',
        format: 'dd/mm/yyyy',
        todayHighlight: false,
        weekStart: 0
    },
    init:function(element, options){
        this.setOptions(options);
        element.datepicker(this.options);
    }
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Once defined, we simply register our component with the behaviour system so it knows how to wire it up when the time comes:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;var App = {
  behaviour: new Framework.Behaviour
};

App.behaviour.addFilters({
  'Component.DatePicker': {
    setup: function (element, options) {
      return new Component.DatePicker(element, options);
    }
  }
)

$(function(){
  var body = $('body');
  App.behaviour.apply(body);
})
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now comes the beauty of it — in your HAML or HTML, you declare the behaviour directly in your markup using a &lt;code&gt;data-behaviour&lt;/code&gt; attribute. When the page loads, only the relevant components are instantiated, and only for the elements that need them.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-haml&quot;&gt;  = listing.input :start_date,
    as: :string,
    label: 'Start Date',
    placeholder: &quot;e.g. #{example}&quot;,
    input_html: { value: (localize(date, format: '%d/%m/%Y')),
      data: {behaviour: 'Component.DatePicker', 'options-component.datepicker' =&amp;gt; '{&quot;startDate&quot; : &quot;' + example + '&quot;}'}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And just like that, our behaviours are neatly attached, scoped, and easy to manage.&lt;/p&gt;
&lt;p&gt;It’s clean. It’s obvious. And it means onboarding a new team member doesn’t require a 2-hour walkthrough of where the JavaScript magic lives — it’s all in the markup and component files.&lt;/p&gt;
&lt;p&gt;This approach meant zero wasted cycles, faster page loads, and a far more maintainable codebase. Behaviourally-aware pages, declarative setup, and modular control over every UI component. In today’s parlance, it’s not far off what Stimulus or Vue’s component system offers — just built years earlier and tailored to our exact needs.&lt;/p&gt;
&lt;p&gt;This is the short version — enough to give you a taste of how it all works. In a follow-up post, I’ll take a deep dive into the full implementation, including sibling systems like the &lt;code&gt;EventBus&lt;/code&gt;, &lt;code&gt;Trigger&lt;/code&gt; logic, Adapters, and more.&lt;/p&gt;
&lt;p&gt;Credit where it’s due: this wasn’t a solo effort. The framework was shaped with the brilliant Paul Schwarz, and together we built something that — dare I say — still holds up surprisingly well in 2025.&lt;/p&gt;
&lt;h3 id=&quot;jquery-isn-t-dead-it-s-just-retired-&quot;&gt;jQuery Isn’t Dead. It’s Just Retired.&lt;/h3&gt;
&lt;p&gt;Do I recommend jQuery for new apps in 2025? Of course not.&lt;br&gt;
But for apps that already have it — and especially those with a system like this layered on top — there's no real reason to tear it out just to chase trends.&lt;/p&gt;
&lt;p&gt;This is the kind of code you keep &lt;em&gt;because&lt;/em&gt; it works — not in spite of it.&lt;/p&gt;
&lt;h3 id=&quot;coming-up-next&quot;&gt;Coming Up Next&lt;/h3&gt;
&lt;p&gt;In Part 2, I’ll take you on a deep dive into the guts of the Behaviour framework: how components are hydrated, how the &lt;code&gt;EventBus&lt;/code&gt; enables decoupled comms between modules, how &lt;code&gt;Trigger&lt;/code&gt; handles custom DOM events, and more.&lt;/p&gt;
&lt;p&gt;It’s a little old-school, sure — but it's also still slick as hell.&lt;/p&gt;
</description>
<category>JavaScript</category>
<guid isPermaLink="true">https://coderlegion.com/7069/why-im-still-using-jquery-in-2025-never-gonna-give-you-up</guid>
<pubDate>Fri, 07 Nov 2025 02:22:24 +0000</pubDate>
</item>
</channel>
</rss>