Skip to content
Advertisement

Category: Questions

Get the current year in JavaScript

How do I get the current year in JavaScript? Answer Create a new Date() object and call getFullYear(): Example usage: a page footer that always shows the current year: See also, the Date() constructor’s full list of methods.

Specify fallback font sizes in CSS?

Is there any way to specify different font sizes for fallback fonts in CSS? I want to do something like this (which obviously does not work): div { font-family: “Arial Narrow”, Arial, Helvetica, sans-serif; font-size: 20px, 18px, 18px, 18px; } The idea being that Arial Narrow would display at 20px if the user has it installed; if not, the browser

How to remove spaces from a string using JavaScript?

How to remove spaces in a string? For instance: Input: Output: Answer This? Example Update: Based on this question, this: is a better solution. It produces the same result, but it does it faster. The Regex s is the regex for “whitespace”, and g is the “global” flag, meaning match ALL s (whitespaces). A great explanation for + can be

Is an empty iframe src valid?

I want an iframe to initially have src as blank and then once the page loads; call a JS function and then set the src value to an actual one.. So is <iframe src=”#” /> valid OR do I need to use something else like javascript:;, etc Answer just <iframe src=’about:blank’></iframe>

How to remove an HTML element using Javascript?

I am a total newbie. Can somebody tell me how to remove an HTML element using the original Javascript not jQuery. index.html myscripts.js What happens when I click the submit button, is that it will disappear for a very very short time and then appear back immediately. I want to completely remove the element when I click the button. Answer

How to replace item in array?

Each item of this array is some number: How to replace some item with a new one? For example, we want to replace 3452 with 1010, how would we do this? Answer Also it is recommend you not use the constructor method to initialize your arrays. Instead, use the literal syntax: You can also use the ~ operator if you

Advertisement