lang
stringclasses
4 values
desc
stringlengths
2
8.98k
code
stringlengths
7
36.2k
title
stringlengths
12
162
JS
I use this code : to save the position of the images ( and it works ) .Then I animate them and move them.Then I use this code : to animate them back to where they belong.in IE ( at least 8 ) it works fine but in Chrome and Firefox it animates 40-50 pixels too much to the left and down ( like its over-animating ) .dont ...
$ ( `` img.cloudcarousel '' ) .each ( function ( i , e ) { coords [ i ] = $ ( e ) .offset ( ) ; } ) ; $ ( `` img.cloudcarousel '' ) .each ( function ( i , e ) { $ ( e ) .animate ( { top : coords [ i ] .top , left : coords [ i ] .left } , 1000 ) ; } ) ;
Animate behaves wierdly in Chrome and Firefox ( ok in IE )
JS
I have values of form as followI want to serialize it to an object by js or jquery.I try use serializeArray and parse to object but no good
< input name= '' Document [ 0 ] [ category ] '' value= '' 12 '' type= '' text '' > < input name= '' Document [ 0 ] [ filename ] '' value= '' abca.png '' type= '' text '' > Document [ 0 ] = { category : 12 filename : 'abca.png ' } ;
Converting DOM elements into Objects
JS
What I KnowNow I know how to add a print stylesheet in the webpage to design the print layout . Its something like : But I do n't want that.In this blog go to any article or post and print preview the page ( with Google Chrome ) . Now if you go down the page ( in save PDF mode ) you will see that extra text is appended...
< link rel= '' text/css '' href= '' /css/print.css '' media= '' print '' / >
How to show something only when user prints ?
JS
For convenience I wrote a simple toJSON prototype , for handling JSON that I know to be safe : I am using it in testing my web-services . Unfortunately even with this simple test : It fails : What do I not know about JavaScript which is causing this issue ?
String.prototype.toJSON = function ( ) { return JSON.parse ( this.valueOf ( ) ) ; } ; var v0 = ' { `` echo '' : '' hello_world '' } '.toJSON ( ) , v1 = { `` echo '' : `` hello_world '' } ; console.log ( v0 == v1 ) ; // falseconsole.log ( v0 === v1 ) ; // falseconsole.log ( v0.echo == v1.echo ) ; // trueconsole.log ( v0...
JSON object ! = JavaScript object ?
JS
I have a question about the .click function in Jquery . I have this code : I expected to add five divs to the `` myTest '' element and for each div the onclick function would show an alert with the corresponding div number . The divs were added properly , but when I click on the divs I always get the alert with the tex...
for ( var i = 0 ; i < 5 ; i++ ) { var divTest = $ ( ' < div > < /div > ' ) ; divTest.text ( `` My Div `` + i ) ; divTest.click ( function ( ) { alert ( `` Alert : Div `` + i ) ; } ) ; $ ( ' # myTest ' ) .append ( divTest ) ; } ​
JQuery .click not working as I expected
JS
I am currently developing a website that is pure javascript and relies heavily on the jQuery & jQuery UI libraries ( this site is not intended for use by a general public , hence progressive enhancement is not a strict requirement for this project ) . I am encountering a significant memory leak on executing the followi...
oDialogBox = $ ( `` < div > ... < /div > '' ) ; /* Add useful things to the dialog box here */oDialogBox.appendTo ( `` body '' ) ; oDialogBox.dialog ( { /* Other dialog box settings here */ close : function ( event , ui ) { oDialogBox.dialog ( `` destroy '' ) ; oDialogBox.remove ( ) ; oDialogBox = null ; } } ) ;
Identify javascript closures with developer tools
JS
I obtained the following trace from Chrome developer tool 's console : It seems the toString ( ) intelligently skipped the recursive part of the object graph . Is this a standard behavior documented somewhere ?
> a = [ 1 ] [ 1 ] > b = [ 2 , a ] [ 2 , Array [ 1 ] ] > a.push ( b ) 2 > a.toString ( ) '' 1,2 , ''
Loop detection in javascript 's built-in functions
JS
I have been following the angular testing Play by Play on PluralSight by John Papa and Ward Bell.I 'm currently getting the following error when I run my specs . Note that I have only included the code that I think is relevant so that I am not overloading this question with irrelevant information . If you need to see m...
AssertionError : expected { Object ( $ $ state ) } to have a property 'length'at Assertion.assertLength ( bower_components/chai/chai.js:1331:37 ) at Assertion.assert ( bower_components/chai/chai.js:4121:49 ) at Context. < anonymous > ( scripts/home/homeController.Specs.js:48:49 ) window.app.controller ( 'homeController...
Mocked service returning Object ( $ $ state ) error
JS
I 've set up a test so I can begin using jQuery in a cakePHP environment but I 'm having a problem before I 've even started.I have twitter bootstrap also but when I had this problem I turned everything off to make sure it was n't that . It wasn't.I 'm testing this in Chrome & Waterfox.When I tried to $ ( ' # test ' ) ...
$ ( document ) .ready ( function ( ) { $ ( ' # test ' ) .click ( function ( ) { alert ( $ ( ' # test ' ) .text ) ; } ) ; } ) ; < span id= '' test '' > test span < /span >
I ca n't even get $ ( ) .text to work properly . Outputs a massive string of code instead
JS
I have seen some examples that show that Firefox supports some kind of JavaScript syntax along the lines of *something* if *expression* ; .As an example of what I 'm talking about , see this MDN article , which contains the following example : My questions are : What name would be given to describe this kind of syntax ...
var evens = [ i for each ( i in range ( 0 , 21 ) ) if ( i % 2 == 0 ) ] ;
*something* if *expression* syntax in JavaScript ( FF )
JS
I 've searched over the internet but nothings seems to be the same with my problem . What I want is to add question numbers for the questions in text field , and numbers should be unique . I 'm trying to check if the array of numbers is exists in an array of number of questions ( e.g . 8 questions ) , then if it is in ...
$ ( document ) .ready ( function ( ) { var try1 ; var arrayLen = $ ( ' # question\\ [ \\ ] ' ) .length ; var numArray = [ ] ; var convertedArray ; for ( i = 1 ; i < = arrayLen ; i++ ) { numArray.push ( i ) ; } $ ( ' # question\\ [ \\ ] ' ) .on ( 'input ' , function ( ) { if ( $ .inArray ( $ ( this ) .val ( ) , numArray...
How to check if values in an array is exists in an array in jquery/javascript
JS
I have three div with same heights equal to 1vh ` . My problem is they appear with different pixel size on screen . Sometimes they look equal but sometimes not , specially it happens after viewport resizing . Please run the snippet to see.I took some screenshot for demonstrating what really happening during resize , as...
.samples { display : flex ; } .container { display : flex ; flex-direction : column ; justify-content : space-between ; align-items : center ; margin:10px 20px ; height : 20vh ; width:20vh ; } .container div { background : # 000 ; width:100 % ; } # set1 div { height : .3vh ; } # set2 div { height : .7vh ; } # set3 div ...
Why ` 1vh ` CSS size resolve to different pixel size on screen
JS
In ( at least ) Firefox Web Console and JSBin , I getNode.js returns `` [ object Object ] '' in both cases . Which behavior is correct according to the spec ? If the first , why ?
> { } + [ ] 0 > a = { } + [ ] '' [ object Object ] ''
Why does ` { } + [ ] ` return a different result from ` a = { } + [ ] ` in Javascript ?
JS
I try to optimize the performance of a node.js application and therefore I am analyzing the behavior of V8 's JIT compiler.When running the application via node -- trace_deopt -- trace_opt -- code_comments -- print_optcode ... , the output contains many recurring lines like the following : How can I find out which java...
[ did n't find optimized code in optimized code map for 0x490a8b4aa69 < SharedFunctionInfo > ]
locate corresponding JS source of code which is not optimized by V8
JS
From this document , Do n't do thisDo this insteadBecause This saves space and unnecessary DOM references.But DOM is just manipulating object in HTML , XHTML or XML . The above has nothing to do with the DOM . Is this wrong ? Or am I missing something ? Can someone help me understand what DOM reference this article is ...
car = new Object ( ) ; car.make = `` Honda '' ; car.model = `` Civic '' ; car.transmission = `` manual '' ; car.miles = 1000000 ; car.condition = `` needs work '' ; car = { make : `` Honda '' , model : `` Civic '' , transmission : `` manual '' , miles : 1000000 , condition : `` needs work '' }
Why do object literals in javascript save unnecessary DOM references ?
JS
I 'm writing above simple script to test the scope , but I got different result in chrome dev tools and jsfiddle.chrome : 'object proto ' ; jsfiddle : 'global ' ; Why ?
window.scope = 'global'Object.prototype.scope = 'object proto'console.log ( scope ) ;
Why the same code give different result in jsfiddle
JS
What do you make of this ? if y = [ ' a ' ] , x [ y ] is the same as doing x [ [ ' a ' ] ] , right ? Can someone explain what 's happening here ? Why does this work ?
var x = { a : 1 } ; //= > { a : 1 } var y = Object.keys ( x ) ; //= > [ ' a ' ] x [ y ] //= > 1 x [ [ ' a ' ] ] ; //= > 1x [ [ [ ' a ' ] ] ] ; //= > 1x [ [ [ [ [ [ [ [ ' a ' ] ] ] ] ] ] ] ] ; //= > 1
Why does accessing an element in an object using an array as a key work ?
JS
What I want to do Like this , Initially the switching scroll.When the current ( active ) element comes to the center , the next element also wants to be able to scroll in the center . When it see the bottom element , the scroll stops and it changes to a switch scroll . Current statusI already have a switch scroll and a...
// Get the center of the height of .mainconst rect = document.getElementsByClassName ( `` main '' ) [ 0 ] .getBoundingClientRect ( ) ; const mainHCenter = rect.top + ( rect.height / 2 ) ; const mainWCenter = rect.left + ( rect.width / 2 ) ; // Get the element at the center of the height of .mainconst centerElm = docume...
How can the next element be scrolled by center when the current element becomes center ?
JS
I am trying to create an MP3 file using Azure Text to Speech . The node file runs , but nothing gets created or outputted . The Node.js docs files and example are n't too goodhttps : //github.com/Azure-Samples/Cognitive-Speech-TTShttps : //docs.microsoft.com/en-us/azure/cognitive-services/speech-service/get-started-tex...
const sdk = require ( `` microsoft-cognitiveservices-speech-sdk '' ) ; var subscriptionKey = `` 809-myazureapikey '' ; var serviceRegion = `` westeurope '' ; // e.g. , `` westus '' function synthesizeSpeech ( ) { const speechConfig = sdk.SpeechConfig.fromSubscription ( subscriptionKey , serviceRegion ) ; const audioCon...
Azure Text to Speech - Not writing to MP3 file using Node.js
JS
I am currently writing a JS rules engine which at one point needs to evaluate boolean expressions using the eval ( ) function.Firstly I construct an equation as such : relation.relatedTrigger.previousValue is the value I want to compare.relation.operator is the operator ( either `` == '' , `` ! = '' , < = , `` < `` , `...
var equation = `` relation.relatedTrigger.previousValue '' + `` `` + relation.operator + `` `` + `` relation.value '' ; return eval ( equation ) ; relation.relatedTrigger.previousValue < = 100 function evaluateRelation ( relation ) { console.log ( `` Evaluating relation '' ) var currentValue ; //if multiple valuesif ( ...
Are there known problems with > = and < = and the eval function in JS ?
JS
I have lots of div elements where I need to recalculate their heights . The divs are inside another div with id= '' content '' .I 'm using jQuery like this : There are about about 1000 divs that are recalculated like that . It takes some time to do this and I understand it is because the layout is recalculated once for...
$ ( `` # content div '' ) .css ( `` height '' , `` *= '' + Math.random ( ) ) ;
How can I manipulate elements without recalculating the layout using jQuery
JS
Apparently this is identical in my Firebug console : andIs this standard ECMAScript behaviour , that the order does n't play a role in comma-separated var assignments ? Edit : The `` mystery '' is solved . I tested the first example first , then cleared the console and ran the second . However , at this time , y and x ...
var x = `` A '' , y = x ; x + y === `` AA '' ; var x = y , y = `` A '' ; x + y === `` AA '' ;
In which order are variables assigned in Javascript ?
JS
This is my HTML Code . I have a Javascript code that executes when someone click on the link with class `` download-button '' The code looks something like thisWhen I click on the download-button link of the second td element , the first td element download-progress-container hides .
< td class= '' name '' > < div class= '' download-ui-container '' > < div class= '' start-download '' > Starting Download.. < /div > < div class= '' download-progress-container '' > < div class= '' download-progress '' > < /div > < /div > < a class= '' save-file '' > Save File < /a > < /div > < a href= '' abc.mp4 '' cl...
how do I select elements of same div as the button clicked
JS
Is there any real difference between the get operator : and using defineProperty : The MDN pages say that compatibility is about the same .
var obj = { get prop ( ) { //insert code here } } ; var obj ; Object.defineProperty ( obj , `` prop '' , { get : function ( ) { //insert code here } }
Is there any effective difference between the get operator and defineProperty ?
JS
Im using ngFacebook by Almog Baku in my current angular app . In test environment it is working fine . But in apk build via phonegap it is n't working . I have included < dependency id= '' cordova-plugin-inappbrowser '' / > andinto my config.xml too but still no InAppBrowser or new tab poping up . My App.js isAnd in my...
< feature name= '' InAppBrowser '' > < param name= '' android-package '' value= '' org.apache.cordova.InAppBrowser '' / > < /feature > < feature name= '' InAppBrowser '' > < param name= '' ios-package '' value= '' CDVInAppBrowser '' / > < /feature > var myApp = angular.module ( 'myApp ' , [ 'ngTouch ' , 'ngRoute ' , 'm...
ngFacebook not working with phonegap
JS
I am using Firebase Cloud Messaging ( FCM ) to send Data messages so that I can handle notification using Service Worker . Now I show the notification using Service Worker and when I click the notification I want to copy the content of notification in the clipboard.When notification is clicked notificationclick event i...
const messaging = firebase.messaging ( ) ; messaging.setBackgroundMessageHandler ( ( payload ) = > { const title = payload.data.title ; const options = { body : payload.data.body } ; return self.registration.showNotification ( title , options ) ; } ) ; self.addEventListener ( 'notificationclick ' , ( event ) = > { cons...
How to copy web notification content to clipboard
JS
I am new to AJAX , I 'm trying to read a whole page and change an element inside it without refreshing.I have a page that looks like this : I am using PHP & JQuery . Whenever I click on any tr , it gets the id and puts the data assigned in the db to that id , on the form . So I can update the user 's data.Obviously whe...
//Capturador de eventos $ ( document ) .ready ( function ( ) { //Clickar en cualquier lado del tr ( menos el ultimo td ) para actualizar ese registro $ ( `` # tablaDatos tr td : not ( : last-child '' ) .click ( function ( ) { if ( confirm ( `` ¿Seguro que desea modificar el registro ? `` ) ) { $ ( `` # idSelected '' ) ...
Ajax newbie learning ( PHP JQuery )
JS
I 'm using React Sortable HOC to move items around . My initial state is an empty array and I need to update the state with a function from React Sortable . This is the original snippet from React Sortable HOC My state and function look like thisWhat ends up happening is no errors , but more colors get added when I att...
onSortEnd = ( { oldIndex , newIndex } ) = > { this.setState ( ( { items } ) = > ( { items : arrayMove ( items , oldIndex , newIndex ) , } ) ) ; } ; const [ colors , setColors ] = useState ( [ ] ) function onSortEnd ( { oldIndex , newIndex } ) { setColors ( [ ... colors , ( { colors } ) = > ( { colors : arrayMove ( colo...
How to use a function within useState
JS
I have an application that uses a datatable with pagination . The user selects a row in the table and a report is displayed below the table . The user may edit the report . If the user attempts to select another row in the table without saving any pending edits , they are warned and given the chance to go back to the p...
//return to previous page dt_table.page ( pageIndexToReturn ) .draw ( 'page ' ) ; //set selection on previously selected row dt_table.row ( rowIndexToReturn , pageIndexToReturn ) .select ( ) ; dt_table.on ( 'page.dt ' , function ( ) { var info = dt_table.page.info ( ) ; var newPageIndex = info.page ; var state = dt_tab...
datatables and pagination and row selection issue
JS
Given the following HTML/JS ( http : //jsfiddle.net/mgs_jsfiddle/gUhm2/ ) A list is shown . By clicking a row , the row 's id is stored into selectedId.I do not understand , why the function isSelected is re-evaluated , when the selectedId is changed . After all , this is no computed . Why is it re-evaluated anyway ?
< div data-bind= '' foreach : users '' > < p data-bind= '' click : $ root.onClick '' > < span data-bind= '' text : id '' > < /span > < span data-bind= '' text : firstName '' > < /span > < span data-bind= '' text : $ root.isSelected ( $ data ) '' > < /span > < /p > < /div > $ ( function ( ) { function ViewModel ( ) { va...
Why does a function behave like a computed ?
JS
I have a collapsed model which show more information about client , and insid it , I have a button , when I click , I do n't get the informations of the specific client , I get data of all clientsapp.js } ) ; modifClient.html
< ion-list ng-repeat= '' x in names '' > < a class= '' item item-icon-left `` > < i class= '' icon ion-android-arrow-dropdown-circle '' ng-model= '' collapsed '' ng-click= '' collapsed= ! collapsed '' > < /i > { { x.Marque } } < /a > < div ng-show= '' collapsed '' > < table > < thead > < td > < label > Code : < /label ...
How to make href in button inside collapse
JS
While creating a small counter based game , I had an array like this : If I tried to access the first index of the array , I would get : @ monners mentioned it might be a reserved word , so I changed the variable name to xstatus and it worked fine.My question is : why would status [ 0 ] return only the first letter of ...
var status = [ `` day '' , '' dusk '' , '' night '' , '' dawn '' ] ; console.log ( status [ 0 ] ) ; //yields `` d ''
Reserved Word Behavior
JS
I looking into validating some file names . But cant figure out correct regexfile names can be anything , but need to check if filename ends with_ underscoreen or ru or cy ( country code 2 letters ) . ( dot ) extensions ( jpeg , jpg , mp4 , png , gif ) so fileFor Now I tried this ( and is working but maybe there is bet...
my_file_dummy_name.jpeg - not validmy_file_dummy_name_en.jpeg - valid / ( \_\w.\.\w+ ) /g / ( \_ [ a-z ] { 2 } \ . [ a-z ] { 3,4 } ) /g
Regex extension and language
JS
I 'm working on the Rosalind problem Mortal Fibonacci Rabbits and the website keeps telling me my answer is wrong when I use my algorithm written JavaScript . When I use the same algorithm in Python I get a different ( and correct ) answer.The inconsistency only happens when the result gets large . For example fibd ( 9...
function fibd ( n , m ) { // Create an array of length m and set all elements to 0 var rp = new Array ( m ) ; rp = rp.map ( function ( e ) { return 0 ; } ) ; rp [ 0 ] = 1 ; for ( var i = 1 ; i < n ; i++ ) { // prepend the sum of all elements from 1 to the end of the array rp.splice ( 0 , 0 , rp.reduce ( function ( e , ...
Javascript is giving a different answer to same algorithm in Python
JS
UPDATEWith the help and suggestions taken from the @ Ziv Weissman and @ Fribu I re-wrote the whole autocomplete function . If anybody needs it he/she can download from here.Thanks StackOverFlow community.I am creating a jquery autocomplete function . The function that I created is working fine with single text box . Bu...
function setUl ( result ) { var $ ul = $ ( ' < ul > ' ) ; if ( result ! == undefined ) { $ .each ( result , function ( k , v ) { $ ul.append ( ' < li data-value= '' ' + v.value + ' '' > ' + v.label + ' < /li > ' ) ; } ) ; } return $ ul ; } $ .fn.autofill = function ( options ) { if ( options == undefined ) { options = ...
Custom autocomplete function in jquery
JS
I 'm trying to get read-only public information from my LinkedIn profile through the javascript API . I currently have this code , which I know is incomplete : I am able to load the linked in successfully , but when perform the IN.API.Raw call I get : which I suspect is because I have not logged into an account with on...
< script > function linkedinAuthorized ( ) { console.log ( `` Linked in authorized '' ) ; } function linkedinLoaded ( ) { console.log ( `` Linked in loaded '' ) ; IN.Event.on ( IN , `` auth '' , linkedinAuthorized ) ; var url = `` /people/~ ? format=json '' ; IN.API.Raw ( ) .url ( url ) .method ( `` GET '' ) .result ( ...
Javascript LinkedIn API read-only on a specific user
JS
I have divided sm image into five different triangles . I 'm trying to change an image 's src attribute value on hover , and show the hovered ' image in the center square.This is what I 'm trying to do , but with SVGs : How to change an image source on hover ? When we hover on each polygon , the center image should cha...
.overlay { background-image : url ( 'https : //picsum.photos/id/118/1000/800 ' ) ; background-repeat : no-repeat ; background-size : cover ; } .overlay use { opacity : 0 ; transition : all 0.4s linear ; } .overlay use : hover { opacity : 1 ; } .vr-head-tilt { position : relative ; } .big img { width : 200px ; height : ...
How to change an image source on hover with SVGs ?
JS
Reading through Invoking a function without parentheses it is stated multiple times in the comments and answers to not use such code in production . Why please ? I am a beginner at JavaScript as you can guess from the question . If someone could phrase their answer in layman 's terms that would be great , though please...
var h = { get ello ( ) { alert ( `` World '' ) ; } } h.ello // Fires up alert `` world '' var h = { set ello ( what ) { alert ( `` Hello `` + what ) ; } } h.ello = `` world '' // Fires up alert `` Hello world ''
Why is it bad to use a function without parentheses in production ?
JS
I 'm trying to implement the negation of the following regular expression in JavaScript : That expression matches on the following:11111-111-1111122-2222-222255-55555-55And not on the following:12-22-334532-44555-3333I want it to do the opposite of those scenarios.I 've tried the following regular expressions and they ...
^ ( \d ) \1+- ( \d ) \1+- ( \d ) \1+ $ ^ ( ? ! ( \d ) \1+- ( \d ) \1+- ( \d ) \1+ ) $ ^ ( ? ! ( \d ) ) \1+- ( ? ! ( \d ) ) \1+- ( ? ! ( \d ) ) \1+ $ ^ ( ? ! ( \d ) \1+ ) - ( ? ! ( \d ) \1+ ) - ( ? ! ( \d ) \1+ ) $
Ca n't negate regular expression
JS
For example , I had an array with 3 numbers : and I need to convert this array to the object : I don ` t want to use `` old-style '' syntax for this , for example : so for now , I ` m using that syntax : But , is there is any way to do this with a straight dectructuring array to object without need of temporary variabl...
var arr = [ 124 , -50 , 24 ] ; { x : 124 , y : -50 , z : 24 } { x : arr [ 0 ] , y : arr [ 1 ] , z : arr [ 2 ] } const [ x , y , z ] = [ ... arr ] ; const obj = { x , y , z } ;
snippet for creating object from destructured array
JS
When I am using jQuery to grab CSS values for objects , each of the browsers ( IE , Mozilla , Chrome , etc ) returns different values.For example , in Chrome , a background image ( .css ( `` background-image '' ) ) returns : Where in Mozilla , it returns : I am having the same problem on other aspects , such as backgro...
url ( http : //i41.tinypic.com/f01zsy.jpg ) url ( `` http : //i41.tinypic.com/f01zsy.jpg '' ) 50 % 50 % 50 % +50 %
CSS - returning different values from different browsers
JS
I 'm trying to remove any character except 0-9 a-z A-Z ... .any obvious reason the above is n't working ?
var file_name = file.name ; file_name = file_name.replace ( / [ ^A-Z0-9\._\- ] /i , `` ) ;
why is n't my javascript .replace ( ) working ?
JS
I have made simple functionality for select ( add check ) div on 1st click and 2nd click it will be remove , I have used `` closest ( ) '' in else condition . Not getting . Please help.For code click hereJS : =
var selected = $ ( '.demo-select ' ) ; selected.click ( function ( ) { $ ( this ) .toggleClass ( 'selected ' ) ; if ( $ ( '.demo-select ' ) .hasClass ( 'selected ' ) ) { //alert ( 1 ) ; $ ( this ) .append ( ' < p class= '' test '' > check < /p > ' ) ; } else { //alert ( 2 ) ; $ ( '.demo-select ' ) .closest ( '.test ' )...
`` closest ( ) '' is not working in else condition
JS
If anyone can think of a better title for this , please do n't hesitate to change it.I am quite new to jQuery and have ran into an issue with filtering elements.I am filtering DIVS with the data- attribute via a checkbox using the change function . My issue is that if I filter on one data attribute ( colour ) and I the...
< div data-brand= '' Nike '' data-price= '' 31 '' data-colour= '' Blue '' > Blue < /div > < div data-brand= '' Nike '' data-price= '' 31 '' data-colour= '' Red '' > Red < /div > Colours : Blue < input type= '' checkbox '' id= '' BlueCB '' checked > Red < input type= '' checkbox '' id= '' RedCB '' checked > Brand : Nike...
Stay filtered if already filtered in Jquery
JS
I have a problem wih my WordPress plugin , I want to insert Gridster into the plugin but it does n't work.Here I am loading the files , which are correctly in the folder.And this is a code sample of the expected output , which of course does n't work too.I tried including it in the templates ' header file as well as in...
function add_my_stylesheet ( ) { wp_enqueue_style ( 'myCSS ' , plugins_url ( '/css/bootstrap.css ' , __FILE__ ) , false ) ; wp_enqueue_style ( `` gridster-style '' , plugins_url ( '/css/jquery.gridster.min.css ' , __FILE__ ) , false ) ; } add_action ( 'admin_print_styles ' , 'add_my_stylesheet ' ) ; function add_my_scr...
Insert Gridster into WordPress template
JS
I am using a range slider with text box , so whenever I slide the range , value gets updated in textbox . Also whenever I change the value in textbox , slider will move accordingly . Using javascript , I am also changing the slider lower color to orange.This is working perfectly when I slide the range manually but faci...
< /head > < /head > < body > < input type= '' range '' min= '' 1 '' max= '' 100 '' step= '' .1 '' value= '' 15 '' id= '' myrange '' class= '' myrange '' > < input type= '' text '' id= '' priceText '' > < /input > < /body > $ ( function ( ) { var style = $ ( `` < style > '' , { type : '' text/css '' } ) .appendTo ( `` h...
How to trigger 'input change ' function depends upon a textbox value using javascript
JS
Here is my code : I 'm trying to use this example I found : I 'm confused on how to use the onClick= '' this.disabled = true ; part because for my code I already have the function called when I wrote onClick . I used onClick= '' clickMe ( ) . Are you allowed to have onClick twice ? I want to use the onClick= '' this.di...
< html > < body > < script > var clicks = 0 ; function clickME ( ) { clicks += 1 ; document.getElementById ( `` clicks '' ) .innerHTML = clicks ; } < /script > < p > Clicks : < a id= '' clicks '' > 0 < /a > < /p > < button type= '' button '' onClick= '' clickME ( ) '' > Click me < /button > < button type= '' button '' ...
Count Click Only Once
JS
The .length property on an array will return the number of elements in the array . For example , the array below contains 2 elements : [ 1 , [ 2 , 3 ] ] // 2 elements , number 1 and array [ 2 , 3 ] Suppose we instead wanted to know the total number of non-nested items in the nested array . In the above case , [ 1 , [ 2...
getLength ( [ 1 , [ 2 , 3 ] ] ) ➞ 3getLength ( [ 1 , [ 2 , [ 3 , 4 ] ] ] ) ➞ 4getLength ( [ 1 , [ 2 , [ 3 , [ 4 , [ 5 , 6 ] ] ] ] ] ) ➞ 6
How to get the length of all non-nested items in nested arrays ?
JS
I was running a program to change some parts of my javascript code when it bugged in the declaration of a var as a function like this : The code itself works , but I was just wondering if it 's ok to remove the `` name '' for all functions that i find like this ( for it does n't break it in the other problem that analy...
var some_function = function name ( args ) { //do stuff } ; var new_function = function ( ) { /*do stuff*/ } ; jQuerySub.fn.init = function init ( selector , context ) { if ( context & & context instanceof jQuery & & ! ( context instanceof jQuerySub ) ) { context = jQuerySub ( context ) ; } return jQuery.fn.init.call (...
Is there any advantage to define function name in `` var new_function = function name ( ) { } ; '' in javascript ?
JS
I have an Ionic 2 app that uses the ionViewCanLeave ( ) navGuard to show a confirmation message . This works fine ; the user is shown a confirmation dialog and can choose to not leave if they want . Here 's the code for it : I now need to check an additional variable here from storage . In order to get that variable I ...
// About to leave ionViewCanLeave ( ) { if ( ! this.allowedToLeave ) { return new Promise ( ( resolve , reject ) = > { let confirm = this.alertCtrl.create ( { title : 'Are you sure ? ' , message : 'Are you sure ? ' , buttons : [ { text : 'OK ' , handler : ( ) = > { this.allowedToLeave = true ; resolve ( ) ; } , } , { t...
How can I nest 2 promises and have ionViewCanLeave wait for the outcome ?
JS
I need to count div each time on mouseover eventhere is example
$ ( document ) .ready ( function ( ) { var thumb = $ ( '.thm-img img ' ) ; var outer = $ ( '.mn-img ' ) ; var full = $ ( '.full-img ' ) ; var count = $ ( '.mn-img img ' ) .length ; var count = $ ( '.mn-img img ' ) .length ; var sc_height = $ ( outer ) .height ( ) ; $ ( thumb ) .mouseover ( function ( ) { console.log ( ...
How to count img tags each time on mouseover event
JS
I 'm trying to move an image around when the user clicks the image and starts moving : DEMOIt works in Chrome , but has strange behaviour in FFHTML : And I handle the javascript as followsJS : ( In my own code I do a little bit more because you are not allowed to move the image outside certain boundaries ) I do n't kno...
< div id= '' parent '' > < img ... . > < /div > var move = false , prevX ; $ ( 'img ' ) .on ( 'mousedown ' , function ( e ) { move = true ; prevX = e.pageX ; } ) .on ( 'mousemove ' , function ( e ) { if ( move === true ) { var x = parseInt ( $ ( this ) .css ( 'left ' ) ) + e.pageX - prevX ; $ ( this ) .css ( 'left ' , ...
css : dragging image does n't work in Firefox
JS
I write the code as follows , After I execute the function , I can able to access Myfunction.myvarHow is it working ? And If I do so , What is the problem hidden in this ? If any problem , please explain context of that .
function Myfunction ( ) { Myfunction.myvar = `` somevar '' ; }
Can I use function as an object inside the same function
JS
Is there a way to specify which object to use for global when invoking eval ( ) ? ( I 'm not asking how to do global eval ( ) . ) This is not working but this illustrates what I would like : The point is that real global bindings are not affected by implicit variable declaration ( i.e . without var keywords ) in the co...
var pseudoGlobal = { } ; eval ( `` x = 12 '' , pseudoGlobal ) ; pseudoGlobal.x ; // 12
Using eval ( ) with a custom global
JS
Every function create new Error Object . So how I can get the preivous errors ? For example this is my code : When I run this , I get only the last error ( `` can not run main function ' ) but I want to get all the previous errors . Do you have any best practive for that ? What I am doing is this : I am asking , of you...
function main ( callback ) { a ( function ( err ) { if ( err ) { callback ( new Error ( ' can not run main function.. ' ) ) ; return } } ) } function a ( callback ) { b ( function ( err ) { if ( err ) { callback ( new Error ( ' can not run b function ' ) ) ; return } } ) } function b ( callback ) { if ( 1 == 2 ) callba...
JS : How to track errors where there are many functions calls
JS
I need a regex that matches a string as the user types it . It 's a bit hard to explain , so let me show what I mean : It should match this string : '' XXXX units '' , where XXXX is any number.But it should also match any substring from the beginning of that string , so : should also match . But of course , this should...
`` 123 '' '' 123 u '' '' 123 uni '' `` 123 xx '' ^\d+ ? u ? n ? i ? t ? s ?
How can I create a `` progressively matching '' regex ?
JS
I have the following 2 functions to pull in , geocode , and place markers in a google map.I keep getting a TypeError : adds [ i ] is undefined , which of course is causing the rest of the map to bomb.Here is my code : DEMO RETURNED DATA FOR adds
// Place Markers on the Mapvar PlaceMarkers = function ( iw , adds , gc ) { var image = { url : `` http : //meatmysite.com/Images/star2.png '' , size : new google.maps.Size ( 24 , 24 ) } ; var aCt = adds.length ; for ( var i = 0 ; i < aCt ; ++i ) { GetLatLng ( gc , adds [ i ] .address , function ( pos ) { if ( pos ) { ...
Google Map Geocoded TypeError in Callback function
JS
whereas I was expecting reverseNice to be `` HSA '' .
var nice = new String ( `` ASH '' ) ; nice ; //String { 0 : `` A '' , 1 : `` S '' , 2 : `` H '' , length : 3 , [ [ PrimitiveValue ] ] : `` ASH '' } var reverseNice = Array.prototype.reverse.call ( nice ) ; reverseNice.toString ( ) ; // `` ASH ''
new String ( ) does not behave like an array like object
JS
I 've built a simple demo ( https : //codepen.io/anon/pen/VgKQoq ) of elements and objects being created when clicking the button : it creates an element and an object of that element is then pushed into an 'objects ' array . When clicking the remove button , the element and object are successfully removed by using ids...
var id = 0 , objects = [ ] , removes ; function createEntry ( ) { id++ ; // create new element , append to # container & create new object var container = document.querySelector ( ' # container ' ) , newEntry = document.createElement ( `` div '' ) , title = 'title text here ' , description = 'description text here ' , ...
Function running too many times after adding event listener
JS
For better accessibility we needed a second alternative set of play/pause controls and ( with the help of user Kento Nishi ) we successfully moved from DEMO A ( with only 1 audio playback control ) to DEMO B ( with duplicated audio playback controls ) .PROBLEM1 The time duration ( far right number ) is broken in DEMO B...
var play = document.getElementsByTagName ( 'play ' ) [ 0 ] ; var pause = document.getElementsByTagName ( 'pause ' ) [ 0 ] ; document.getElementsByTagName ( `` playpause '' ) [ 0 ] .addEventListener ( `` click '' , playpause ) ; document.getElementsByTagName ( `` playpause '' ) [ 1 ] .addEventListener ( `` click '' , pl...
Why using a source tag inside an audio tag prevents the loadeddata event from firing ?
JS
How can I chunk array by element ? For example lodash has this function chunking arrays by lengthsSo I have an array like this [ ' a ' , ' b ' , '* ' , ' c ' ] can I do something likewhich will give me It is something like string split for array
_.chunk ( [ ' a ' , ' b ' , ' c ' , 'd ' ] , 2 ) ; // = > [ [ ' a ' , ' b ' ] , [ ' c ' , 'd ' ] ] _.chunk ( [ ' a ' , ' b ' , ' c ' , 'd ' ] , 3 ) ; // = > [ [ ' a ' , ' b ' , ' c ' ] , [ 'd ' ] ] chunk ( [ ' a ' , ' b ' , '* ' , ' c ' ] , '* ' ) [ [ ' a ' , ' b ' ] , [ ' c ' ] ]
Chunk array by element
JS
Here 's an example that uses Backbone with React.He defines a Model : var _todos = new Backbone.Model ( ) ; And then adds two functions to it : What I do n't understand is why areAllComplete is being applied to a Model instead of to a Collection.Should n't this be a function in a Collection that will get all of its mod...
var TodoStore = _.extend ( _todos , { areAllComplete : function ( ) { return _.every ( _todos.keys ( ) , function ( id ) { return _todos.get ( id ) .complete ; } ) ; } , getAll : function ( ) { return _todos.toJSON ( ) ; } } ) ;
Confusion about Models in Backbone + React application
JS
I have added a function using Function.prototype.func = ... to Function but in Firefox it has not been added console.log : Is it a bug or is there any reason for that ?
Function.prototype.func = function ( ) { return this.toString ( ) ; } ; alert ( typeof console.log.func ) ; // in FF : undefined , in Chrome : function
Why in Firefox Function.prototype.func= ... does n't affect console.log ?
JS
I tried to console variable fullName after function run , but it does n't changed value , just console default value Not Set , why was that ?
function Test ( ) { this.clientData = { fullName : `` Not Set '' , setUserName : function ( firstName , lastName ) { this.fullName = firstName + `` `` + lastName ; } , getUserInput2 : function ( firstName , lastName , callback ) { callback ( firstName , lastName ) ; } } ; this.getUserInput1 = function ( firstName , las...
instance function variable is not changed ?
JS
I am loading a set of images from another page using jquery load ( ) function . I want the images that are loaded to be able to trigger the colorbox script but it is not working . I have all of the scripts on the page that triggers the load , but the script does not get applied to the fresh ajax content . How could I m...
< a href= '' http : //something.com '' class= '' cbox '' > < img ... / > < /a > $ j ( `` .cbox '' ) .on ( `` click '' , function ( ) { $ j.fn.colorbox ( { iframe : true , scrolling : false , innerWidth : '650px ' , innerHeight : '390px ' } ) ; return false ; } ) ;
Load scripts along with content in ajax
JS
I 'm working on this function that has to return all possible values of adding a and b n times for example if n = 1 then possible values would be a + a a + b and b + b. function below works but it 's too slow and I want to optimize it . Any suggestions ? Thanks a lot !
function processData ( n , a , b ) { var ans = [ 0 ] ; for ( var i = 0 ; i < n ; i++ ) { var temp = [ ] ; for ( var j = 0 ; j < ans.length ; j++ ) { var aa = ans [ j ] + a ; if ( temp.includes ( aa ) === false ) { temp.push ( aa ) ; } var bb = ans [ j ] + b ; if ( temp.includes ( bb ) === false ) { temp.push ( bb ) ; }...
Need to Optimize the function
JS
I would like to save my openlayers map as PDF.Unfortunately all the options I tried do n't work.The first option , I guess the easiest one was here : https : //jsfiddle.net/Ljnya5gp/1/from which I developed something like this : but the script downloads only blank document for me.I want to have this section downloaded ...
function createPdf ( ) { var doc = new jsPDF ( ) ; source = $ ( ' # map ' ) [ 0 ] ; specialElementHandlers = { ' # map ' : function ( element , renderer ) { return true } } ; doc.fromHTML ( source , 15 , 15 , { 'width ' : 170 , 'elementHandlers ' : specialElementHandlers } ) ; doc.save ( 'Area 5 map - alterations.pdf '...
Save Openlayers map as PDF ( offline version )
JS
I 'm trying to create a matrix in Javascript , but one which has predefined keys for the X and Y axis . For example I have the following keysI found the following snippet which creates an empty two dimensional array with 4 rows and 5 columnsI 'm wondering if it 's possible to create these arrays ( objects ) , but using...
const x = [ 2,4,6,8 ] const y = [ 10,20,40,60,80 ] [ ... Array ( 4 ) ] .map ( x= > Array ( 5 ) .fill ( 0 ) ) { 2 = > { 10 = > 0 , 20 = > 0 , 40 = > 0 , 60 = > 0 , 80 = > 0 } 4 = > { 10 = > 0 , 20 = > 0 , 40 = > 0 , 60 = > 0 , 80 = > 0 } 6 = > { 10 = > 0 , 20 = > 0 , 40 = > 0 , 60 = > 0 , 80 = > 0 } 8 = > { 10 = > 0 , 2...
Create an empty two dimensional array in Javascript , with keys
JS
Possible Duplicate : Get variable from a string I have an array called myArray and a variable which is called myVar . The myVar variable holds a value 'myArray ' ( value of myVar equals the arrays name ) . Can I somehow access the arrays elements using the myVar variable ? Some code to explain what I mean : Thanks !
var myArray = { 1 , 2 , 3 } ; var myVar = `` myArray '' ;
JavaScript : access array with the same name as a variable ?
JS
I 'm looking for a vanilla JavaScript solution.Say I 've got a function with the following header : I need to run it like this : I would like to be able to call it with argument map instead of positional arguments , i.e.And I 'm looking for an already-written solution to do this in JavaScript , since I 've got an unlim...
generateEmail ( firstName , lastname , provider ) generateEmail ( `` John '' , '' Smith '' , '' gmail.com '' ) ; generateEmail ( { `` firstName '' : '' John '' , `` lastname '' : `` Smith '' , `` provider '' : `` gmail.com '' } ) ;
JavaScript function arguments : positional - > map transition
JS
I have been playing with backbone and trying to learn it . I 'm stuck at this point for a while . Not able to figure out what 's wrong with following code ?
render : function ( ) { this. $ el.empty ( ) ; // render each subview , appending to our root element _.each ( this._views , function ( sub_view ) { this. $ el.append ( sub_view.render ( ) .el ) ; // Error on this line } ) ;
Why this render function does n't work ?
JS
I was reading an article about Javascript 's best practices , and kinda got confused about which function structure to use ... I guess it might have an impact on the scope of the variables and functions , but which one of these structures would you use ( and which is considered the best practice ) ? Structure 1 : use t...
var obj1 = { _myvar : 'myval ' , init : function ( ) { this.function1 ( ) ; this.function2 ( ) ; } , function1 : function ( ) { alert ( 'function1 ' ) ; } , function2 : function ( ) { alert ( 'function2 ' ) ; } } ; obj1.init ( ) ; ( function ( ) { var _myvar = 'myval ' , function1 = function ( ) { alert ( 'function1 ' ...
Javascript : which function structure to use
JS
Suppose I have a class with many methods , but I know for sure that their signature matches.Is it possible to describe the interface of this class without describing the specific methods of this class in it ? Like here : Or is it impossible ?
interface IController { ( input : string ) : number // any method without reference to its name } class Controller implements IController { method1 ( input : string ) : number { ... do something } method2 ( input : string ) : number { ... do something } ... }
Declare interface of class only with methods signature without names
JS
I have an array of objects : I need to cumulate the value and keep the same array with updated valuesThe result would look like thisI am aware that this existsBut I can not find an example with object returning also objects
var myArray = [ { `` date '' : `` 03/01/2017 '' , `` value '' : 2 } , { `` date '' : `` 04/01/2017 '' , `` value '' : 6 } , { `` date '' : `` 05/01/2017 '' , `` value '' : 4 } ] ; var myArray = [ { `` date '' : `` 03/01/2017 '' , `` value '' : 2 } , { `` date '' : `` 04/01/2017 '' , `` value '' : 8 // ( 2+6 ) } , { `` ...
Javascript cumulate an array of object to an array of object
JS
For some reason , when I splice an object into my ng-repeat array , it doubles what I splice in and hides the last object in the array.However , if I click the toggle hide and `` refresh '' the ng-repeat , it shows the right data.Does anyone know why this would be happening and what I can do to fix it ?
angular.module ( 'app ' , [ ] ) .controller ( 'ctrl ' , function ( $ scope ) { $ scope.workflow = { flow : [ { `` id '' : `` 1334f68db820f664 '' , `` step_number '' : 1 , `` tasks '' : [ { `` id '' : `` 1334f68e3f20f665 '' } ] } , { `` id '' : `` 134967a5ba205f5b '' , `` step_number '' : 2 , `` tasks '' : [ { `` id '' ...
ng-repeat splice showing double
JS
When I try to run below code in javascript , the browser hangs because of catastrophic backtracking which loops infinitely probably because of a poorly designed regular expression . I need either an alternative expression or a way to prevent this issue :
string temp = `` Testing robustness { parent-area-identifier Some text in between the tokens { parent-area-label } '' ; var strRegExp = new RegExp ( / [ { ] ( ? : [ ^ { } ] +| [ { ] [ ^ { } ] * [ } ] ) * [ } ] /g ) ; var arrMatch = temp.match ( strRegExp ) ;
How can I make the regular expression not result in “ catastrophic backtracking ” ?
JS
I 'm using ar.js which uses the users webcam and issues a permission prompt to do so . What I want is to listen to a global event triggered by this dialogue if the user either allows or denies access to the webcam or has done so previously . I 've tried with global listeners like : WebRTC errors on MDN references only ...
document.documentElement.addEventListener ( `` error '' , e= > { console.log ( `` GOT ERROR : `` , e ) } ) window.addEventListener ( `` error '' , e= > { console.log ( `` GOT ERROR : `` , e ) } ) ;
How to listen to a global event triggered by WebCam Error : NotAllowedError
JS
I want to set javascript variable with single quote . How it is possible . I am passing value to my function as parameter . and I am using this value to retrieve value of checkbox . So my problem is that if I am alerting value then it give me 'user ' instead of 'sanjay ' Here 'sanjay ' is my value which is I am passing...
function single ( user ) { var abc = '\ ' user \ '' ; alert ( abc ) ; return false ; var chksingle = document.getElementById ( abc ) .checked ; alert ( chksingle ) ; return false ; if ( userlist ( ) === false ) { return false ; } else { document.tallyexport.method = `` post '' ; document.tallyexport.action = `` checksi...
how to set single quote in javascript
JS
I have 3 objects in an array in which all of them have an equal number of data properties . The data is as follows : The data is representation of date values in a month ( So they have equal length ) . What I want is to get the sum of values of alternate data of each dates and get the maximum value out of it . Alternat...
const monthStats = [ { name : 'pending ' , data : [ ' 5 ' , ' 1 ' , ' 2 ' , ' 3 ' , '100 ' , ' 0 ' , ' 0 ' , ' 0 ' , ' 0 ' , ' 0 ' , ' 0 ' , ' 0 ' , ' 0 ' , ' 0 ' , ' 0 ' , ' 0 ' , '20 ' , ' 0 ' , ' 0 ' , ' 0 ' , ' 0 ' , ' 0 ' , ' 0 ' , ' 0 ' , ' 0 ' , ' 0 ' , ' 0 ' , ' 0 ' , ' 0 ' , ' 0 ' , ' 0 ' ] , } , { name : 'del...
( JavaScript ) Get the sum of alternate values in array and get the maximum value from it
JS
I 'm looking to write a JavaScript function which takes the following data structure as an argument : As you can see , the data structure is an array of objects . The objects each contain a single property . Each of these properties is either a `` value '' with a string or a `` delay '' with another array of the same t...
let data = [ { value : ' a ' } , { delay : [ { value : ' b ' } , { delay : [ { value : ' c ' } ] } ] } , { value : 'd ' } ] ; abcd
recursive asynchronous JavaScript for nested data structure processing
JS
Is it 100 % safe to do the following ? : Considering that the third party can input anything ( HTML , CSS , etc . ) , can I be sure it wo n't do any harm if I pass it through createTextNode and then add it to the dom ?
var untrusted_input_from_3rd_party = ' < script > alert ( `` xss '' ) < \/script > ' ; document.getElementsByTagName ( 'body ' ) [ 0 ] .appendChild ( document.createTextNode ( untrusted_input_from_3rd_party ) ) ;
Is it 100 % safe to do the following ?
JS
I am a bit clueless about the next task . I wish to select a text between `` that its inside a tag but not outside of the tag , i.e . a selection inside another selection.I have the next tag : < | and | > and i want to select a text only if its between the `` and between the tags. < | blah blah blah `` should be select...
( \ < \| ) ( \ '' ) .* ? ( \ '' ) ( \|\ > )
Regular expression , selects a portion of text inside other
JS
I want to better understand how objects in Ruby have access methods defined in classes and modules . Specifically , I want to compare and contrast it with JavaScript ( which I 'm more familiar with ) .In JavaScript , objects look up methods on the object itself and if it ca n't find it there , it 'll look for the metho...
// JavaScript Examplevar parent = { someMethod : function ( ) { console.log ( 'Inside Parent ' ) ; } } ; var child = Object.create ( parent ) ; child.someMethod = function ( ) { console.log ( 'Inside Child ' ) ; } ; var obj1 = Object.create ( child ) ; var obj2 = Object.create ( child ) ; obj1.someMethod ( ) ; // 'Insi...
Ruby Method Lookup ( comparison with JavaScript )
JS
I have two directories src and compiled . I would like to ensure one-way data synchronization from src to compiled with Grunt Watch . As an intermediary step , I would like to compile *.less files as well as a subset of *.js files which are written with ES6 syntax.I 've successfully written the tasks which do what I ne...
// NOTE : Spawn must be disabled to keep watch running under same context in order to dynamically modify config file.watch : { // Compile LESS files to 'compiled ' directory . less : { options : { interrupt : true , spawn : false , cwd : 'src/less ' } , files : [ '**/*.less ' ] , tasks : [ 'less ' ] } , // Copy all non...
Deep , one-way synchronization of two directories using grunt-contrib-watch . Code works , but grunt-contrib-watch re-init time is too slow
JS
I 'm developing a website that can draw graphs using konva , but I 'm currently running into this weird problem : If I change the unit per tick to anything other than *.5 or an integer , it will become something like this : Here 's the code : https : //codepen.io/ItsTheWolf/pen/jrdkNXHere 's the HTML5 code if it helps ...
var stage , axeslayer , gridslayer , axes , grids , errTxt ; var w , h ; var linex , liney ; var centx , centy ; var maxx , maxy , miny ; var x , y ; var distx , disty ; var i , j ; var tg = 1 , err = 0 ; document.getElementById ( 'togG ' ) .disabled = true ; // disable button Toggle Gridsfunction draw ( ) { getValues ...
Validating value in HTML number input with Konva
JS
This doesnt work = ( , even if I try new Array ( ) or anything else . Is it not possible to do arrays within arrays ? This is what I was going for : I know I can do something likeBut this does n't make it as easy to readAm I doing something wrong ? I 've tried every possible combination I could think of and using googl...
HeroName = new Hero ( ) HeroName.Spells = [ ] ; HeroName.Spells [ 0 ] .Type = [ ] ; HeroName.Spells [ 0 ] .Type [ 0 ] = new DmgSpell ( ) ; HeroName.Spells [ 0 ] .Type [ 1 ] = new Buff ( ) ; HeroName.Spells [ 0 ] [ 0 ] = new DmgSpelL ( ) ; HeroName.Spells [ 0 ] [ 1 ] = new Buff ( ) ;
Array within an array , within an object ?
JS
When I execute the below test HTML page in Chrome , I see the following in the debug console : Am I right in assuming that this a Chrome bug ( it does n't happen in other browsers ) , or is Chrome within its right to do this for some reason ? It resulted in a bug in one of my web apps and I finally isolated this snippe...
Has parent ? trueHas parent ? false < ! DOCTYPE HTML > < html > < head > < meta charset= '' UTF-8 '' > < title > < /title > < /head > < body class= '' '' > < script > function testDoodle ( ) { var testParentEl = document.createElement ( 'div ' ) ; var testChildEl = testParentEl.appendChild ( document.createElement ( 'd...
parentNode being lost on Javascript inner closure ? Chrome bug ?
JS
In all of the JavaScript operator precedence charts I can find ( like this one and this one ) , the logical AND ( & & ) has slightly higher precedence to the logical OR ( || ) .I ca n't seem to figure out an expression where the result is different than it would be if they had the same precedence . I figure there must ...
0 || 2 & & 0 || 3 ( 0 || 2 ) & & 0 || 30 || ( 2 & & 0 ) || 3 ( 0 || 2 & & 0 ) || 30 || 2 & & ( 0 || 3 ) 0 || ( 2 & & 0 || 3 ) 0 || false & & `` '' || NaN 0 || false & & ( `` '' || NaN )
Example of expression where the precedence of AND ( & & ) over OR ( || ) matters ?
JS
The other day , I came across some weird code : The intention of the code was clear to me : It was the try to define a constructor function , in order to create an instance of OrderSupplement . I am baffled by this syntax.The buddy , who wrote the code , said it worked fine - although it obviously does not ; at least i...
var OrderSupplement = function ( ) { oid : null ; code : `` '' ; description : `` '' ; startdate : `` '' ; enddate : `` '' ; gender : null ; cardowner : null ; box : null ; divisor : 0 ; created : null ; createdBy : `` '' ; } ; var OrderSupplementJson = function ( ) { }
Why does JavaScript parser accept JSON as a function body ?
JS
I use Gem Coocon for nested forms.I need to hide the # end_date_job_portfolio field if .checkBoxCurrentJob is checked . The problem is that jQuery can ` t see the tags if the user didn ` t click add new nested form because these tags aren ` t in document yet . For this I use the cocoon : after-insert . This my script :...
$ ( document ) .ready - > checkbox_date = `` '' end_date = `` '' $ ( '.experiences ' ) .on 'cocoon : after-insert ' , - > checkbox_date = $ ( `` .checkBoxCurrentJob '' ) end_date = $ ( ' # end_date_job_portfolio ' ) console.log ( checkbox_date ) # show it when the checkbox is clicked сheckbox_date.on 'click ' , - > con...
Declare global variable in coffescript
JS
I am trying to make a submenu using jQuery . The idea is that when someone clicks on the first menu a submenu appears , then when someone clicks the submenu it disappears and shows a div with information but I cant make it work properly.Here is my HTML : And this is my jQuery : The idea is simple , if menu is clicked a...
< ul id= '' menu '' > < li > < a href= '' # '' > Item 1 < /a > < ul id= '' submenu '' > < li > < a href= '' # '' data-menu= '' show1 '' > Sub menu 1 < /a > < /li > < li > < a href= '' # '' data-menu= '' show2 '' > Sub menu 2 < /a > < /li > < /ul > < /li > < /ul > < div id= '' show1 '' class= '' content '' > Lorem ipsum...
Ca n't show content text from menu using jQuery
JS
I have been reviewing other people 's code and while ES2015 on the whole is taking some getting use to , however , I keep on getting stuck with Destructuring.Previously , In Javascript , the Curly Brackets { } were either used for blocks or objects . e.g.However , in destructuring , we see again and again the following...
// Curly Brackets BlockIf ( ) { ... } // Curly Brackets in Objvar obj = { a : 1 , ... } let a = ( { a , b } ) = > { } let a = ( a , b ) = > { } let a = { first : a , second : b } = AnObj ; ===a.a === AnObj.first ; a.b === AnObj.second ;
Understanding the Context of Curly Brackets ' { } '
JS
I got zero instead of one , which part I missed out ? I want to remove the class name or do some styling to myhtml .
$ ( function ( ) { myhtml = ' < tr > < td > 1 < /td > < td > Orange < /td > < td > 1799.00 x < span > 1 < /span > < /td > < td > 0.00 < /td > < td > 1799.00 < /td > < /tr > < tr class= '' shippingRow '' > < td > < /td > < td > < /td > < td > < /td > < td > Shipping < /td > < td > 2.00 < /td > < /tr > < tr class= '' tot...
select class of raw html
JS
For a object have multiple attributes , for example , a shoe may have different color , size and etc.Now when we tried to display the shoe , and make the customer can choose different attributes , we use radio ( the simplest ) : https : //jsfiddle.net/mwqy6217/But how to make the availability of the view according to t...
var options= [ [ `` A1 '' , '' B1 '' , '' C1 '' , '' D1 '' ] , [ `` A1 '' , '' B3 '' , '' D2 '' ] , [ `` A2 '' , '' B1 '' , '' C3 '' , '' D2 '' ] ] ;
Dynamical view according to data
JS
I am creating a parallel coordinates plot using d3.js , but am struggling to format axis labeling as I would like.For instance , one of my axes , 'Buffer Concentration ' , is plotted on a log scale , which I 've specified through the dimensions variable , like so.However , as you can see from the resulting plot below ,...
var dimensions = [ ... { key : `` b.Conc '' , description : `` Buffer Concentration '' , type : types [ `` Number '' ] , scale : d3.scale.log ( ) .domain ( [ .1 , 100 ] ) .range ( [ innerHeight , 0 ] ) , tickValues : [ .1 , .2 , .4 , .6 , .8,1,2,4,6,8,10,20,40,60 ] , tickFormat : d3.format ( 4 , d3.format ( `` , d '' )...
Why are .domain , tickFormat and tickValues not recognised inside dimensions variable ? ( d3 , parallel coordinates )
JS
I was busting my head on this problem for some time ... I have a usual constructor/prototype object ( like a class ) in js which holds all of my d3 chart logic : for the constructor , and for the methods something like thisand the problem is in the zoomProcess method which always returns ( logs ) HTML element on the th...
figureGen = function ( html_element ) { this.svg = d3.select ( html_element ) .append ( 'svg ' ) .style ( 'width ' , '100 % ' ) .style ( 'height ' , '100 % ' ) .append ( ' g ' ) .attr ( `` class '' , `` sadrzalac '' ) .attr ( `` transform '' , `` translate ( `` + 0 + `` , '' + 0 + `` ) '' ) ; this.element = element ; t...
Unusual d3 zoom in reusable class - this and bind
JS
I do n't mean to be vague , but I 'm not sure what is going on.This code works : It produces : As you can see there is plenty of room on the right border . What you may not notice is that all my content is off centered by about 5px . To fix this I thought I would just decrease the jquery dialog width by 5px as such : H...
this.J.button_update.click ( function ( ) { self.J.dialog_hold.dialog ( { resizable : false , modal : true , width : 305 , height : 360 } ) ; } ) ; width : 300 , // decreased by 5
`` Something '' is breaking this jqueryui dialog . What is it ?
JS
I wrote a silly example to see which of the two , the click or the submit event , fires first on an input of type submit.When I run it , though , nothing is written to the console.Stepping through the code in the debugger reveals the following series of occurrences.It fires the click event handler first , writes the te...
( function ( ) { let btn = document.getElementById ( `` btnSave '' ) ; btn.addEventListener ( `` click '' , function ( event ) { console.log ( `` click '' ) ; } , false ) ; btn.addEventListener ( `` submit '' , function ( event ) { console.log ( `` submit '' ) ; // event.preventDefault ( ) ; } , false ) ; console.log (...
Submit event of a submit type input is n't triggered
JS
So I was looking at how I could display a Desktop Notification using a Google Chrome extensions when I came across these lines of code : What the heck does all of this do ?
var time = / ( .. ) ( : .. ) / ( Date ( ) ) ; // The prettyprinted time.var hour = time [ 1 ] % 12 || 12 ; // The prettyprinted hour.var period = time [ 1 ] < 12 ? ' a.m . ' : ' p.m . ' ; // The period of the day .
How does this JavaScript statement calculate the date ?
JS
I have two comma-separated selectors ; I 'd like to be able to select any possible combination between these two groups . So it would select elements matchingHow can I achieve this effectively ?
.class , .foo , .bar.lorem , .ipsum , .potato .class.lorem.class.ipsum.class.potato.foo.lorem.foo.ipsum.foo.potato.bar.lorem.bar.ipsum.bar.potato
Match all combinations of any classes in jQuery