Skip to content
Advertisement

Tag: javascript

Substring text with HTML tags in Javascript

Do you have solution to substring text with HTML tags in Javascript? For example: Answer Taking into consideration that parsing html with regex is a bad idea, here is a solution that does just that 🙂 EDIT: Just to be clear: This is not a valid solution, it was meant as an exercise that made very lenient assumptions about the

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>

Advertisement