I know that in PHP 5.3 instead of using this redundant ternary operator syntax: …we can use a shorthand syntax for our ternary operators where applicable: And I know about the ternary operator in JavaScript: …but is there a shorthand? Answer Something like that what you’re looking for, where…
Tag: javascript
HTML Select: How can you change the label when the is closed?
Consider this: The HTML above looks like #1 when open, and #2 when closed. How can I get the closed version to look like #3? The purpose is to also show the selected year without repeating it in the open options (so it looks cleaner). Answer My original (marked correct) answer is too old to be of use, so here
Use CMYK on web page
I need to use CMYK colors on my web page. Is there any way to use CMYK in CSS or may be convert CMYK to RGB using JavaScript? EDIT: I mean I have colors creating algorithm in CMYK notation and I need to use it on web page. Answer There is no perfect algorithmic way to convert CMYK to RGB.
How do I remove properly html5 audio without appending to DOM?
With Javascript, I have a function that creates an audio element with createElement(“audio”), and start playing in loop without using appendChild(), I mean without appending it to the DOM. The element created is kept in a variable, let’s called it music1: What I would like to do, is to chang…
Logical operator in a handlebars.js {{#if}} conditional
Is there a way in handlebars JS to incorporate logical operators into the standard handlebars.js conditional operator? Something like this: I know I could write my own helper, but first I’d like to make sure I’m not reinventing the wheel. Answer This is possible by ‘cheating’ with a bl…
How to convert JSON to CSV format and store in a variable
I have a link that opens up JSON data in the browser, but unfortunately I have no clue how to read it. Is there a way to convert this data using JavaScript in CSV format and save it in JavaScript file? The data looks like: The closest I could find was: Convert JSON format to CSV format for MS Excel
How to get 30 days prior to current date?
I have a start calendar input box and an end calendar input box. We want defaults start calendar input box 30 days prior to current date and the end calendar input box to be the current date. Here is my date vars. The end date would be something like var enddate = startdate – 30; Obviously this won̵…
Sort array of objects by single key with date value
I have an array of objects with several key value pairs, and I need to sort them based on ‘updated_at’: What’s the most efficient way to do so? Answer You can use Array.sort. Here’s an example:
How to efficiently check if variable is Array or Object (in NodeJS & V8)?
Is there any way to efficiently check if the variable is Object or Array, in NodeJS & V8? I’m writing a Model for MongoDB and NodeJS, and to traverse the object tree I need to know if the object is simple (Number, String, …) or composite (Hash, Array). It seems that V8 has fast built-in Array.…
How to get selected month in jQuery full calendar?
We are using jQuery full calendar for displaying events from database. I need to display the events below the calendar according to user selected month onchange. I can get data according to event date but I can’t get user selected month in jQuery calendar. This is the calendar function I am using, I nee…