Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 6502

JavaScript is a versatile, high-level programming language. It is the programming language in all browsers.and can be used for back-end programming with node.js. Use this tag for questions regarding vanilla JavaScript; optionally tagged with an ECMAScript version. If you are using a preprocessor such as TypeScript please tag with that too.

3 votes
Accepted

Varying a second drop-down's options based on a first selection

For starters, you can remove a lot of duplicate code from the populateBilling() function like this: function populateBilling(planName) { var options = { basic: { "Option" : [ …
jfriend00's user avatar
  • 3,948
1 vote
Accepted

Should I write my fadeTo function differently?

Well written animation functions typically use a tweening algorithm that checks the system clock to see how much time is actually remaining in the originally specified time allotment and then adjusts …
jfriend00's user avatar
  • 3,948
7 votes
Accepted

Declaring JavaScript variable and then overwriting it multiple times

You can using chaining, move the toLowerCase() to simplify a little and return the last statement directly: function() { var el = {{element}}; el = (el.innerText || el.textContent); …
jfriend00's user avatar
  • 3,948
6 votes
Accepted

Reducing code with two identical objects

You can combine the two identical assignments at the end into the same line rather than recalculating the same value again: for (var i = 0; i < ticks.length && i < ticks2.length; i++) { var tick …
jfriend00's user avatar
  • 3,948
2 votes

Javascript assert function

You could write it as: function safeLog(s) { if (window.console && window.console.log) { console.log(s); } } function assert(a, b, message) { if (a != b) { safeLog("Faile …
jfriend00's user avatar
  • 3,948
1 vote
Accepted

Should I change the following to switch or else if statements?

else if would be more efficient because it wouldn't continue to evaluate comparisons that you already know won't match. It would also be more efficient to cache some values here so you aren't reval …
jfriend00's user avatar
  • 3,948
3 votes
Accepted

Showing and hiding element, making my code more useful

Item 1: I'd suggest getting rid of all global variables except tog. They don't look like they are needed and just open you up for a potential conflict with other global variables. Item 2: This line …
jfriend00's user avatar
  • 3,948
1 vote
Accepted

JavaScript function for printing a countdown

Try this: var time_format = (function() { var names = "yr mo w d h m s".split(" "); return function(time) { var elms, ret, i, n; elms = [ time / 29030400, …
jfriend00's user avatar
  • 3,948
1 vote

New to immediately-invoked function expression with JavaScript, curious about placement

In this case, it makes no difference at all. This IIFE really has no reason for even being there because all it contains is a single function. Your code does use any of the usual benefits of an IIFE …
jfriend00's user avatar
  • 3,948
3 votes
Accepted

Maximum number of values in an array

There is no native way to do this so your general logic seems sound. Here's some improvements, you might consider: Make sure the pushMax function is not enumerable so people who iterate arrays with …
jfriend00's user avatar
  • 3,948
2 votes

Copying and pasting one inputs value into other input with the same name

Why not at least save the intermediate to avoid rerunning that: $(document).on('click', '.--copy', function () { var obj = $(this).closest('div').find('input'); var input_name = obj.attr('nam …
jfriend00's user avatar
  • 3,948
5 votes
Accepted

Input text sizing function

Here's how you could use a table array for the widths. I didn't fill in all the character widths (I just did lowercase) because it's tedious to build, but you can extend it to contain all the typeabl …
jfriend00's user avatar
  • 3,948
11 votes
Accepted

Check if a JavaScript variable exists and checking its value

First off, your code really breaks down to this logic and I find it helpful to write it out the longer version to full understand the logic flow before trying to shorten it: var header_cookie, cookie …
jfriend00's user avatar
  • 3,948
1 vote

Does this function have to be nested?

If you place your code in a script tag at the end of the body, right before the </body> tag, then the code can just be this: document.getElementById('addChllng').addEventListener('click', function() …
jfriend00's user avatar
  • 3,948
5 votes
Accepted

Acquiring and formatting data from a JSON file

I'd suggestion cleaning it up like this: function MCScrap(ZWA, ZWB, ZWC, ZWD, Number) { $(document).ready(function () { setInterval(function () { $.getJSON("mccount.json", fun …
jfriend00's user avatar
  • 3,948

1
2 3 4 5 6
15 30 50 per page