nodejs fs.exists()

I’m trying to call fs.exists in a node script but I get the error: TypeError: Object # has no method ‘exists’ I’ve tried replacing fs.exists() with require(‘fs’).exists and even require(‘path’).exists (just in case), but neither of these even list the method exists() with my IDE. fs is declared at the top of my script as […]

Is this javascript snippet considered bad?

I like making my code as succinct as possible but maybe this is unreadable? var filters = {}; function addFilter(type, name) { filters[type] && filters[type].push(name) || ( filters[type] = [name] ); } or even (as pointed out in answers): var filters = {}; function addFilter(type, name) { filters[type] ? filters[type].push(name) : ( filters[type] = [name] […]

Adding the same code to multiple functions

I am facing a situation where I need to add the same blocks of code to the start and the end of multiple functions in JavaScript. e.g. function funcA () { // code block 1 … // code unique to funcA … // code block 2 … } function funcB () { // code block […]

Angular+Jquery – Programmatic form submit causes redirect

I’m trying to write a form which has ngsSubmit. Pressing Enter and clicking the submit button works as expected (calling the method I provided for ng-submit and that’s that). However, I also want in some cases to do some preprocessing before actually submitting, so I tried using JQuery’s submit() to programmatically trigger the submit. This […]

JavaScript: querySelector Null vs querySelector

What is the main difference between these two methods of referencing? What are the benefits of using one or the other? Also what kind of usage-case would they each be best suited to? var selection = document.querySelector(‘.selector’) !== null; var selection = document.querySelector(‘.selector’); Is the former solely for browser legacy support?

Uncaught ReferenceError for a function defined in an onload function

HTML: <div id=”myID” onclick=”cc(this.id)”>Click Here</div>​ JavaScript: var timer; var firing = false; var begen = function(id) { alert(‘tek’); }; var popupAc = function(id) { alert(‘çift’); }; function cc(id) { if (firing) { popupAc(id); clearTimeout(timer); firing = false; return; } firing = true; timer = setTimeout(function() { //begen(id); clearTimeout(timer); firing = false; }, 250); } Error: […]

What's the better practice to put <a> in <tr>

Between this two practices, what’s the better? <tr onclick=”window.document.location=’http://link.com’;”> <td>Lorem ipsum.</td> <td>Lorem ipsum.</td> <td>Lorem ipsum.</td> <td>Lorem ipsum.</td> <td>Lorem ipsum.</td> <td>Lorem ipsum.</td> <td>Lorem ipsum.</td> <td>Lorem ipsum.</td> Or <tr> <td><a href=”http://link.com”>Lorem ipsum.</a></td> <td><a href=”http://link.com”>Lorem ipsum.</a></td> <td><a href=”http://link.com”>Lorem ipsum.</a></td> <td><a href=”http://link.com”>Lorem ipsum.</a></td> <td><a href=”http://link.com”>Lorem ipsum.</a></td> </tr> I want to use only JavaScript. In the first way I repeat […]

Click event is not working for dynamically added button

I reffered Creating a div element in jQuery and creatd a div element using javascript. However when I added a button element dynamically, click is not working. What change do we need to do to make the button click working? Note: We cannot move the function outside of document.ready due to kendo control requirements mentioned […]

angular2 – skip first item in ngFor

I want to skip the first item with ngFor: <li *ngFor=”#m +1 of [1,2,3,4]”>{{m}}</li> the output should be: 2,3,4 What is the best way to do this in Angular2?

Using innerHTML to detect the number of occurrences of a character?

I’ve been using this code to detect elements in a table that contain a semicolon and then change the background colour: var x = document.getElementsByTagName(“TD”); var i=0; for (i=0;i<x.length;i++) { if (x[i].className==”ms-vb-title”) { if (x[i].innerHTML.indexOf(“;”) != -1) { x[i].style.cssText=”background-color:#ccc !important;”; } } } But I now want to change the colour based on the number […]