Java Script

JavaScript (not to be confused with Java) is a high-level, dynamic, multi-paradigm, weakly-typed language used for both client-side and server-side scripting. Its primary use is in rendering and allowing manipulation of web pages. Use this tag for questions regarding ECMAScript and its various dialects/implementations (excluding ActionScript and Google-Apps-Script).

58 votes
30 answers
1.4K 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?

avatar
Luis
0 1 0 9
asked 07 September, 2021
50 votes
30 answers
590 views
56 votes
30 answers
2.5K views
What is the JavaScript version of sleep()?

Is there a better way to engineer a sleep in JavaScript than the following pausecomp function (taken from here

avatar
Rufus
0 1 0 9
asked 07 September, 2021
57 votes
30 answers
1.6K 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)

avatar
Deedee
0 1 0 9
asked 07 September, 2021
47 votes
21 answers
1.9K views
Is it possible to apply CSS to half of a character?

What I am looking for: A way to style one HALF of a character. (In this case, half the letter being transpare

avatar
Clarice
0 1 0 9
asked 07 September, 2021
65 votes
30 answers
2K views
How can I convert a string to boolean in JavaScript?

Can I convert a string representing a boolean value (e.g., 'true', 'false') into a intrins

avatar
Bryant
0 1 0 9
asked 07 September, 2021
63 votes
30 answers
2.9K views
Creating multiline strings in JavaScript

I have the following code in Ruby. I want to convert this code into JavaScript. What is the equivalent code in

avatar
Royal
0 1 0 9
asked 07 September, 2021
56 votes
30 answers
2.2K views
JavaScript closure inside loops – simple practical example

var funcs = []; // let's create 3 functions for (var i = 0; i < 3; i++) { // and store them in f

avatar
Shanita
0 1 0 9
asked 07 September, 2021
57 votes
30 answers
2K views
Detecting an undefined object property

What's the best way of checking if an object property in JavaScript is undefined?

avatar
Mikki
0 1 0 9
asked 07 September, 2021
57 votes
30 answers
2.6K views
How can I upload files asynchronously with jQuery?

I would like to upload a file asynchronously with jQuery. $(document).ready(function () { $("#uploa

avatar
Dario
0 1 0 9
asked 07 September, 2021
56 votes
30 answers
2.3K views
How can I change an element&apos;s class with JavaScript?

How can I change the class of an HTML element in response to an onclick or any other events using JavaScript?

avatar
Dorinda
0 1 0 9
asked 07 September, 2021
50 votes
30 answers
1.9K views
How can I check if an object is an array?

I'm trying to write a function that either accepts a list of strings, or a single string. If it's a

avatar
Trudy
0 1 0 9
asked 07 September, 2021
51 votes
14 answers
2.7K 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 tw

avatar
Vi
0 1 0 9
asked 07 September, 2021
63 votes
30 answers
1K views
How do I loop through or enumerate a JavaScript object?

I have a JavaScript object like the following: var p = { "p1": "value1", "p2": "value2", "p3": "v

avatar
Santiago
0 1 0 9
asked 07 September, 2021
51 votes
25 answers
3.1K views
What is the difference between call and apply?

What is the difference between using call and apply to invoke a function? var func = function() { alert(&ap

avatar
Solomon
0 1 0 9
asked 07 September, 2021
54 votes
25 answers
1.6K views
Get the current URL with JavaScript?

All I want is to get the website URL. Not the URL as taken from a link. On the page loading I need to be able

avatar
Bryan
0 1 0 9
asked 07 September, 2021
71 votes
30 answers
2.9K views
How to round to at most 2 decimal places, if necessary?

I'd like to round at most 2 decimal places, but only if necessary. Input: 10 1.7777777 9.1 Output: 1

avatar
Lashawna
0 1 0 9
asked 07 September, 2021
52 votes
30 answers
1.1K views
How can I check for an empty/undefined/null string in JavaScript?

I saw this question, but I didn't see a JavaScript specific example. Is there a simple string.Empty avail

avatar
Elicia
0 1 0 9
asked 07 September, 2021
60 votes
30 answers
595 views
Sort array of objects by string property value

I have an array of JavaScript objects: var objs = [ { first_nom: 'Lazslo', last_nom: 'Jam

avatar
Daniel
0 1 0 9
asked 07 September, 2021
53 votes
30 answers
1.5K views
How do I correctly clone a JavaScript object?

I have an object x. I'd like to copy it as object y, such that changes to y do not modify x. I realized t

avatar
Hallie
0 1 0 9
asked 07 September, 2021