jQuery how to find an element based on a data-attribute value?

I’ve got the following scenario: var el=”li”; and there are 5 <li>‘s on the page each with a data-slide=number attribute (number being 1,2,3,4,5 respectively). I now need to find the currently active slide number which is mapped to var current = $(‘ul’).data(current); and is updated on each slide change. So far my tries have been … Read more

Set select option ‘selected’, by value

I have a select field with some options in it. Now I need to select one of those options with jQuery. But how can I do that when I only know the value of the option that must be selected? I have the following HTML: <div class=”id_100″> <select> <option value=”val1″>Val 1</option> <option value=”val2″>Val 2</option> <option … Read more

How can I get the ID of an element using jQuery?

<div id=”test”></div> <script> $(document).ready(function() { alert($(‘#test’).id); }); </script> Why doesn’t the above work, and how should I do this? 1 19 The jQuery way: $(‘#test’).attr(‘id’) In your example: $(document).ready(function() { console.log($(‘#test’).attr(‘id’)); }); <script src=”https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script> <div id=”test”></div> Or through the DOM: $(‘#test’).get(0).id; or even : $(‘#test’)[0].id; and reason behind usage of $(‘#test’).get(0) in JQuery or even … Read more

jQuery: datepicker alternative

Is there a better, smaller alternative to the jQuery datepicker? The ui.datepicker.js has app. 70kb which is pretty huge imo. Could it be compressed? you don’t need the whole ui library just http://jqueryui.com/download disable the other stuff or you can use google ajax api cdn. the best alternative to jui datepicker is the html5 datepicker with is … Read more