Questions tagged [jquery]

jQuery is a JavaScript library. jQuery is a popular cross-browser JavaScript library that facilitates Document Object Model (DOM) traversal, event handling, animations, and AJAX interactions by minimizing the discrepancies across browsers. A question tagged jQuery should be related to jQuery, so jQuery should be used by the code in question, and at least jQuery usage-related elements must be in the question. Consider also adding the JavaScript tag.

Filter by
Sorted by
Tagged with
8619 votes
65 answers
3.2m views

How do I check if an element is hidden in jQuery?

How do I toggle the visibility of an element using .hide(), .show(), or .toggle()? How do I test if an element is visible or hidden?
Philip Morton's user avatar
7702 votes
58 answers
7.7m views

How do I redirect to another webpage?

How can I redirect the user from one page to another using jQuery or pure JavaScript?
venkatachalam's user avatar
5150 votes
68 answers
4.8m views

How do I check whether a checkbox is checked in jQuery?

I need to check the checked property of a checkbox and perform an action based on the checked property using jQuery. For example, if the age checkbox is checked, then I need to show a textbox to enter ...
4557 votes
44 answers
3.8m views

Setting "checked" for a checkbox with jQuery

I'd like to do something like this to tick a checkbox using jQuery: $(".myCheckBox").checked(true); or $(".myCheckBox").selected(true); Does such a thing exist?
tpower's user avatar
  • 56.1k
4506 votes
15 answers
853k views

"Thinking in AngularJS" if I have a jQuery background? [closed]

Suppose I'm familiar with developing client-side applications in jQuery, but now I'd like to start using AngularJS. Can you describe the paradigm shift that is necessary? Here are a few questions that ...
Mark Rajcok's user avatar
3265 votes
15 answers
6.1m views

Why does my JavaScript code receive a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error, while Postman does not?

Mod note: This question is about why XMLHttpRequest/fetch/etc. on the browser are subject to the Same Access Policy restrictions (you get errors mentioning CORB or CORS) while Postman is not. This ...
Mr Jedi's user avatar
  • 33.8k
3230 votes
14 answers
933k views

event.preventDefault() vs. return false

When I want to prevent other event handlers from executing after a certain event is fired, I can use one of two techniques. I'll use jQuery in the examples, but this applies to plain-JS as well: 1. ...
RaYell's user avatar
  • 69.7k
3134 votes
34 answers
1.5m views

How can I upload files asynchronously with jQuery?

I would like to upload a file asynchronously with jQuery. $(document).ready(function () { $("#uploadbutton").click(function () { var filename = $("#file").val(); $.ajax({...
Sergio del Amo's user avatar
3128 votes
47 answers
861k views

Is there an "exists" function for jQuery?

How can I check the existence of an element in jQuery? The current code that I have is this: if ($(selector).length > 0) { // Do something } Is there a more elegant way to approach this? ...
Jake McGraw's user avatar
  • 55.6k
3052 votes
40 answers
2.5m views

How can I know which radio button is selected via jQuery?

I have two radio buttons and want to post the value of the selected one. How can I get the value with jQuery? I can get all of them like this: $("form :radio") How do I know which one is selected?
juan's user avatar
  • 80.4k
2921 votes
91 answers
1.7m views

How do I detect a click outside an element?

I have some HTML menus, which I show completely when a user clicks on the head of these menus. I would like to hide these elements when the user clicks outside the menus' area. Is something like this ...
2732 votes
20 answers
3.1m views

How do I refresh a page using JavaScript?

How do I refresh a page using JavaScript?
luca's user avatar
  • 36.7k
2687 votes
33 answers
3.1m views

Scroll to an element with jQuery

I have this input element: <input type="text" class="textfield" value="" id="subject" name="subject"> Then I have some other elements, like ...
DiegoP.'s user avatar
  • 45.2k
2654 votes
42 answers
2.0m views

Adding a table row in jQuery

I'm using jQuery to add an additional row to a table as the last row. I have done it this way: $('#myTable').append('<tr><td>my data</td><td>more data</td></tr>'); ...
Darryl Hein's user avatar
2651 votes
34 answers
3.4m views

How can I determine if a variable is 'undefined' or 'null'?

How do I determine if a variable is undefined or null? My code is as follows: var EmpName = $("div#esd-names div#name").attr('class'); if(EmpName == 'undefined'){ // DO SOMETHING }; <...
sadmicrowave's user avatar
2535 votes
19 answers
2.6m views

Disable/enable an input with jQuery?

$input.disabled = true; or $input.disabled = "disabled"; Which is the standard way? And, conversely, how do you enable a disabled input?
omg's user avatar
  • 137k
2517 votes
35 answers
2.3m views

Get selected text from a drop-down list (select box) using jQuery

How can I get the selected text (not the selected value) from a drop-down list in jQuery?
haddar's user avatar
  • 25.4k
2488 votes
18 answers
719k views

.prop() vs .attr()

So jQuery 1.6 has the new function prop(). $(selector).click(function(){ //instead of: this.getAttribute('style'); //do i use: $(this).prop('style'); //or: $(this).attr('style'...
Naftali's user avatar
  • 145k
2423 votes
21 answers
2.1m views

Get the size of the screen, current web page and browser window

How can I get windowWidth, windowHeight, pageWidth, pageHeight, screenWidth, screenHeight, pageX, pageY, screenX, screenY which will work in all major browsers?
turtledove's user avatar
  • 25.5k
2405 votes
19 answers
2.0m views

How to get the children of the $(this) selector?

I have a layout similar to this: <div id="..."><img src="..."></div> and would like to use a jQuery selector to select the child img inside the div on click. To get the div, I've ...
Alex's user avatar
  • 26.5k
2400 votes
38 answers
1.3m views

$(document).ready equivalent without jQuery

I have a script that uses $(document).ready, but it doesn't use anything else from jQuery. I'd like to lighten it up by removing the jQuery dependency. How can I implement my own $(document).ready ...
FlySwat's user avatar
  • 173k
2327 votes
54 answers
3.0m views

Remove duplicate values from JS array [duplicate]

I have a very simple JavaScript array that may or may not contain duplicates. var names = ["Mike","Matt","Nancy","Adam","Jenny","Nancy",&...
kramden88's user avatar
  • 23.5k
2273 votes
14 answers
1.1m views

How can I select an element with multiple classes in jQuery?

I want to select all the elements that have the two classes a and b. <element class="a b"> So, only the elements that have both classes. When I use $(".a, .b") it gives me the union, but I ...
Mladen's user avatar
  • 25.6k
2153 votes
42 answers
804k views

How do I format a Microsoft JSON date?

I'm taking my first crack at Ajax with jQuery. I'm getting my data onto my page, but I'm having some trouble with the JSON data that is returned for Date data types. Basically, I'm getting a string ...
2104 votes
30 answers
1.7m views

Preview an image before it is uploaded

I want to be able to preview a file (image) before it is uploaded. The preview action should be executed all in the browser without using Ajax to upload the image. How can I do this?
Simbian's user avatar
  • 21.3k
2033 votes
31 answers
2.5m views

Get current URL with jQuery? [duplicate]

I am using jQuery. How do I get the path of the current URL and assign it to a variable? Example URL: http://localhost/menuname.de?foo=bar&amp;number=0
venkatachalam's user avatar
1982 votes
18 answers
702k views

Abort Ajax requests using jQuery

Is it possible that using jQuery, I cancel/abort an Ajax request that I have not yet received the response from?
lukewm's user avatar
  • 21.5k
1943 votes
64 answers
1.9m views

How to detect a mobile device using jQuery

Is there a way to detect whether or not a user is using a mobile device in jQuery? Something similar to the CSS @media attribute? I would like to run a different script if the browser is on a handheld ...
1907 votes
16 answers
1.4m views

How to move an element into another element

I would like to move one DIV element inside another. For example, I want to move this (including all children): <div id="source"> ... </div> into this: <div id="...
Mark Richman's user avatar
1866 votes
10 answers
2.2m views

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

With jQuery, we all know the wonderful .ready() function: $('document').ready(function(){}); However, let's say I want to run a function that is written in standard JavaScript with no library ...
chris's user avatar
  • 36.2k
1759 votes
58 answers
1.1m views

Convert form data to JavaScript object with jQuery

How do I convert all elements of my form to a JavaScript object? I'd like to have some way of automatically building a JavaScript object from my form, without having to loop over each element. I do ...
1675 votes
23 answers
1.1m views

Event binding on dynamically created elements?

I have a bit of code where I am looping through all the select boxes on a page and binding a .hover event to them to do a bit of twiddling with their width on mouse on/off. This happens on page ready ...
Eli's user avatar
  • 97.6k
1668 votes
20 answers
2.6m views

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?
fearofawhackplanet's user avatar
1643 votes
24 answers
2.0m views

Creating a div element in jQuery [duplicate]

How do I create a div element in jQuery?
useranon's user avatar
  • 29.3k
1531 votes
61 answers
2.8m views

How to find the sum of an array of numbers

Given an array [1, 2, 3, 4], how can I find the sum of its elements? (In this case, the sum would be 10.) I thought $.each might be useful, but I'm not sure how to implement it.
akano1's user avatar
  • 40.7k
1520 votes
15 answers
2.2m views

How can I select an element by name with jQuery?

I have a table column I’m trying to expand and hide. jQuery seems to hide the <td> elements when I select it by class but not by the element’s name. For example: $(".bold").hide(); // ...
T.T.T.'s user avatar
  • 33.4k
1520 votes
34 answers
1.1m views

How to manage a redirect request after a jQuery Ajax call

I'm using $.post() to call a servlet using Ajax and then using the resulting HTML fragment to replace a div element in the user's current page. However, if the session times out, the server sends a ...
Elliot Vargas's user avatar
1490 votes
37 answers
1.1m views

What is the best way to add options to a select from a JavaScript object with jQuery?

What is the best method for adding options to a <select> from a JavaScript object using jQuery? I'm looking for something that I don't need a plugin to do, but I would also be interested in the ...
Darryl Hein's user avatar
1479 votes
27 answers
2.6m views

Check if checkbox is checked with jQuery

How can I check if a checkbox in a checkbox array is checked using the id of the checkbox array? I am using the following code, but it always returns the count of checked checkboxes regardless of id. ...
Jake's user avatar
  • 25.5k
1472 votes
8 answers
1.7m views

Check if element exists in jQuery [duplicate]

How do I check if an element exists if the element is created by .append() method? $('elemId').length doesn't work for me.
Nick's user avatar
  • 15.8k
1452 votes
13 answers
1.7m views

How to change the href attribute for a hyperlink using jQuery

How can you change the href attribute (link target) for a hyperlink using jQuery?
Brian Boatright's user avatar
1385 votes
35 answers
2.2m views

jQuery Get Selected Option From Dropdown

Usually I use $("#id").val() to return the value of the selected option, but this time it doesn't work. The selected tag has the id aioConceptName html code <label for="name">...
William Kinaan's user avatar
1385 votes
17 answers
1.2m views

window.onload vs $(document).ready()

What are the differences between JavaScript's window.onload and jQuery's $(document).ready() method?
Vaibhav Jain's user avatar
  • 33.9k
1374 votes
46 answers
904k views

How to check if element is visible after scrolling?

I'm loading elements via AJAX. Some of them are only visible if you scroll down the page. Is there any way I can know if an element is now in the visible part of the page?
yoavf's user avatar
  • 20.9k
1355 votes
15 answers
1.0m views

jQuery document.createElement equivalent?

I'm refactoring some old JavaScript code and there's a lot of DOM manipulation going on. var d = document; var odv = d.createElement("div"); odv.style.display = "none"; this.OuterDiv = odv; var t = ...
Rob Stevenson-Leggett's user avatar
1344 votes
18 answers
1.5m views

How do I set/unset a cookie with jQuery?

How do I set and unset a cookie using jQuery, for example create a cookie named test and set the value to 1?
omg's user avatar
  • 137k
1325 votes
14 answers
824k views

How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request?

I have a JavaScript widget which provides standard extension points. One of them is the beforecreate function. It should return false to prevent an item from being created. I've added an Ajax call ...
Artem Tikhomirov's user avatar
1285 votes
23 answers
1.1m views

jQuery get specific option tag text

All right, say I have this: <select id='list'> <option value='1'>Option A</option> <option value='2'>Option B</option> <option value='3'>Option C</...
Paolo Bergantino's user avatar
1233 votes
11 answers
928k views

Serializing to JSON in jQuery [duplicate]

I need to serialize an object to JSON. I'm using jQuery. Is there a "standard" way to do this? My specific situation: I have an array defined as shown below: var countries = new Array(); countries[0]...
Herb Caudill's user avatar
  • 50.1k
1229 votes
28 answers
1.4m views

How do you remove all the options of a select box and then add one option and select it with jQuery?

Using core jQuery, how do you remove all the options of a select box, then add one option and select it? My select box is the following. <Select id="mySelect" size="9"> </Select> EDIT: ...
Jay Corbett's user avatar
  • 28.1k

1
2 3 4 5
20766