Posts

Showing posts with the label jQuery

jQuery UI - Dialog - How to hide autofocus

The simplest way, just add hidden input with autofocus attribute . < input type ="hidden" autofocus > As it said in jQuery UI documentation, it will find this input firstly by priority and move focus on this input. But as this input hidden user does not see this. Choosing priority: The first element with the autofocus attribute The first :tabbable element within the dialog's content The first :tabbable element within the dialog's buttonpane The dialog's close button The dialog itself

Javascript - jQuery - Make menu item Active automatically

There is, as minimum, two ways how to add 'active' class to menu item, to highlight it. First one is on backend side. Second one is on frontend side. Now, I talk about variant with frontend side. So, I choose javascript to decide to add 'active' class to menu item or not. There is a code for this: var pathName = window.location.pathname; // Iterate through each anchor tag within list items $("ul li a").each(function () { // Check if the href attribute matches the current URL if ($(this).attr("href") == pathName) { // If there is a match, traverse up the DOM hierarchy to find the corresponding list item $(this).parents('li').each(function () { // Add the 'active' class to highlight the menu item $(this).addClass("active"); }); } }); This script essentially loops through all anchor "a" tags within list items "li" in the specified unordered list "ul". For each a...

JavaScript - jQuery - How to get array values from multiple select

There are various ways to retrieve the selected values from a "<select>" element in jQuery.  The simplest method involves using the "val()" function, like so: $('select').val();  However, this straightforward approach has its limitations, particularly when it comes to manipulating the selected data.  If you require more control and flexibility in handling the selected options, you can leverage the power of the map function: $('select option:selected').map((index, option) => option.value).get(); In this enhanced method, the map function allows you to iterate through the selected options, providing you with greater control over the extraction process.  The addition of the ":selected" filter in the selector ensures that only the chosen options are considered, enhancing the precision of your selection process. This proves invaluable when dealing with scenarios where you need to perform specific actions or manipulations based on the sel...