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

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 $(‘#test’)[0] is that $(‘#test’) is a JQuery selector and returns an array() of results not a single element by its default … Read more

Convert form data to JavaScript object with jQuery

serializeArray already does exactly that. You just need to massage the data into your required format: function objectifyForm(formArray) { //serialize data function var returnArray = {}; for (var i = 0; i < formArray.length; i++){ returnArray[formArray[i][‘name’]] = formArray[i][‘value’]; } return returnArray; } Watch out for hidden fields which have the same name as real inputs … Read more

Vanilla JavaScript equivalent of jQuery’s $.ready() – how to call a function when the page/DOM is ready for it [duplicate]

The simplest thing to do in the absence of a framework that does all the cross-browser compatibility for you is to just put a call to your code at the end of the body. This is faster to execute than an onload handler because this waits only for the DOM to be ready, not for … Read more

How to move an element into another element?

You may want to use the appendTo function (which adds to the end of the element): $(“#source”).appendTo(“#destination”); Alternatively you could use the prependTo function (which adds to the beginning of the element): $(“#source”).prependTo(“#destination”); Example: $(“#appendTo”).click(function() { $(“#moveMeIntoMain”).appendTo($(“#main”)); }); $(“#prependTo”).click(function() { $(“#moveMeIntoMain”).prependTo($(“#main”)); }); #main { border: 2px solid blue; min-height: 100px; } .moveMeIntoMain { border: 1px … Read more

How to detect a mobile device using jQuery

Editor’s note: user agent detection is not a recommended technique for modern web apps. See the comments below this answer for confirmation of this fact. It is suggested to use one of the other answers using feature detection and/or media queries. Instead of using jQuery you can use simple JavaScript to detect it: if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera … Read more

Abort Ajax requests using jQuery

Most of the jQuery Ajax methods return an XMLHttpRequest (or the equivalent) object, so you can just use abort(). See the documentation: abort Method (MSDN). Cancels the current HTTP request. abort() (MDN). If the request has been sent already, this method will abort the request. var xhr = $.ajax({ type: “POST”, url: “some.php”, data: “name=John&location=Boston”, … Read more

Get current URL with jQuery?

To get the path, you can use: var pathname = window.location.pathname; // Returns path only (/path/example.html) var url = window.location.href; // Returns full URL (https://example.com/path/example.html) var origin = window.location.origin; // Returns base URL (https://example.com)

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)