lang stringclasses 4
values | desc stringlengths 2 8.98k | code stringlengths 7 36.2k | title stringlengths 12 162 |
|---|---|---|---|
JS | I have a JSON object like so : I am looping through this object and creating info cards containing the title of each workout ( `` Full Body '' , `` God Legs '' etc ) .Upon clicking one of the cards , I would like to be able to store the exercises associated with each title into a variable for further use . For example ... | { `` workouts '' : [ { `` title '' : `` Full Body '' , `` exercises '' : [ { `` name '' : `` Push Ups '' , `` duration '' : 3 , `` break '' : 3 } , { `` name '' : `` Squats '' , `` duration '' : 3 , `` break '' : 3 } , { `` name '' : `` Running in Place '' , `` duration '' : 3 , `` break '' : 3 } ] } , { `` title '' : ... | Store specific JSON array in variable |
JS | I am rendering scatter plot using ZingChart.render ( ) method . It is working fine and giving me the expected result.I want to execute some code after graph rendering is completed . Since the JS code gets executed in an asynchronous manner , the code which I want to execute after graph rendering gets executed before th... | zingchart.render ( { id : 'chartDiv ' , data : chartData , height:400 , width:600 } ) ; performance.now ( ) | Invoke callback function after zingChart.render ( ) |
JS | I want to build a proxy that detects changes to an object : New properties are defined.Existing properties are changed.Code Sample 1 - definePropertyCode Sample 1 - Observationsproxy has a property name which is what I 'd expect.Changing the name property tells me that name has been defined ; not what I 'd expect.Defin... | const me = { name : `` Matt '' } const proxy = new Proxy ( me , { defineProperty : function ( target , key , descriptor ) { console.log ( ` Property $ { key } defined. ` ) ; return Object.defineProperty ( target , key , descriptor ) ; } } ) ; proxy // { name : 'Matt ' } proxy.name = `` Mark '' ; // Property name define... | JavaScript - Proxy set vs. defineProperty |
JS | I am using Enhanced Ecommerce to monitor events of a step-by-step checkout process.Note : Triple confirmed that EC is enabled on the Analytics Property , and Checkout Funnel Labels have been set ( albeit the latter being not required anyway ) When a user clicks the `` Next step '' button on step 1 , the following code ... | ga ( 'ec : setAction ' , 'checkout ' , { step : 1 } ) ; ga ( 'send ' , 'event ' , 'Checkout ' , 'Customer Proceeding to Select Accomodation ' ) | Data not appearing in Shopping Analysis |
JS | HTML : JS// hides the slickbox as soon as the DOM is ready ( a little sooner that page load ) CSSNow the above functionality is what I want to achieve using purely CSS , which is when I hover over the `` wxyz '' button `` abcd '' button should come down and stay visible even is mouse is moved away from `` wxyz '' for ... | < div id= '' slick-slidetoggle '' > wxyz < /div > < div id= '' slickbox '' > abcd < /div > var hoverVariable=false ; var hoverVariable2=false ; $ ( ' # slickbox ' ) .hide ( ) ; $ ( ' # slick-slidetoggle ' ) .mouseover ( function ( ) { hoverVariable2=true ; $ ( ' # slickbox ' ) .slideToggle ( 600 ) ; return false ; } ... | Convert jquery animation to CSS3 |
JS | Given a large array of positive integer `` weights '' , e.g . [ 2145 , 8371 , 125 , 10565 , ... ] , and a positive integer `` weight limit '' , e.g . 15000 , I want to partition the weights into one or more smaller arrays , with the following criteria : I want to minimize the number of partitions.No single partition ca... | function minimizePartitions ( weights , weightLimit ) { let currentPartition = [ ] ; let currentSum = 0 ; let partitions = [ currentPartition ] ; for ( let weight of weights ) { if ( currentSum + weight > weightLimit ) { currentPartition = [ ] ; currentSum = 0 ; partitions.push ( currentPartition ) ; } currentPartition... | Partitioning weighted elements with a restriction on total partition weight |
JS | In a multi-chart dc.js/d3.js presentation , I wish to trap user click on a datapoint in the first chart , and : identify all points in chart 1 with a value within 30 points of the clicked point ; -- donestore the indices for these data points ; -- donecolorize the stored datapoints in chart1 ; -- need helpcolorize the ... | clearconsole ( ) ; var chartWidth = 500 ; var myCSV = [ { `` shift '' : '' 1 '' , '' date '' : '' 01/01/2016/08/00/00 '' , '' car '' : '' 178 '' , '' truck '' : '' 125 '' , '' bike '' : '' 317 '' , '' moto '' : '' 237 '' } , { `` shift '' : '' 2 '' , '' date '' : '' 01/01/2016/17/00/00 '' , '' car '' : '' 125 '' , '' t... | dc.js add class to data points in multiple charts based on criteria from first chart |
JS | What do I miss that a is not added to the beginning of the textarea ? The purpose is to genuinely simulate an actual press of a key on the keyboard , NOT ( re ) setting the textarea value.UPDATE : This is not a duplicate of this question . ( i ) Most of the answers use jQuery . ( ii ) I could n't find a working example... | var el = document.getElementById ( 'action ' ) ; el.addEventListener ( 'click ' , function ( ) { var t = document.getElementById ( 'text ' ) ; t.value = ' A should be typed later ' ; t.focus ( ) ; t.setSelectionRange ( 0 , 0 ) ; setTimeout ( function ( ) { t.dispatchEvent ( new Event ( 'keypress ' , { keyCode : 65 } ) ... | Dispatching a KeyboardEvent fails to produce the character in a textarea |
JS | File loader.js : File window.html : Console output when I open this HTML page : My question : In the above code , is it guaranteed that the script onload event always fires before the window onload ? | function main ( ) { if ( typeof window ! == 'undefined ' ) { var script = window.document.createElement ( 'script ' ) script.src = 'https : //cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.core.min.js ' script.onload = function ( ) { console.log ( 'script loaded ' ) } window.onload = function ( ) { console.log... | Is order of script onload and window.onload well defined when the script is a DOM node created dynamically from a loaded script ? |
JS | I sometimes need to find out the computed value of the HTML lang attribute ( the element 's language ) . I 'm using jQuery . For example , in the following code I 'd like to know the computed lang of the < p > element , and I would expect the value he : Doing $ ( ' p ' ) .attr ( 'lang ' ) returns nothing , probably bec... | < ! DOCTYPE html > < html lang= '' en '' dir= '' ltr '' > < head > < meta charset= '' utf-8 '' / > < title > lang test < /title > < /head > < body > < div lang= '' ar '' > < div lang= '' he '' > < p > Hallo. < /p > < /div > < /div > < /body > < /html > $ ( ' p ' ) .closest ( ' [ lang ] ' ) .attr ( 'lang ' ) | How to find out the computed value of an element 's lang attribute in JavaScript ? |
JS | Consider this script : Not exactly the expected output , however when I update to this : This seems to work , and I 've no idea why . Can anybody enlighten me ? Thanks | function Obj ( prop ) { this.prop = prop ; } var NS = { strings : [ 'first ' , 'second ' , 'third ' ] , objs : [ ] , f1 : function ( ) { for ( s in this.strings ) { var obj = new Obj ( this.strings [ s ] ) ; obj.f2 = function ( ) { alert ( obj.prop ) ; } this.objs.push ( obj ) ; } } } NS.f1 ( ) ; NS.objs [ 0 ] .f2 ( ) ... | JavaScript : lexical closure or something else ? |
JS | I 'm using PanoJS in a Rails 4 project and I get the following error : What I 'm confused about is that the method seems to be declared just a few lines above.I 've raised it as an issue with PanoJS but I 'm suspicious it 's simply a configuration error between Rails and Javascript . I have previously had it set up and... | TypeError : this.getLevel ( ... ) is undefined [ panojs/pyramid_imgcnv.js ] [ 1 ] Line 92 % div { id : `` image_viewer '' , class : `` viewer '' , data : { } } jQuery ( document ) .ready ( $ ) - > $ ( ' # zoomimage ' ) .addimagezoom largeimage : $ ( ' # zoomimage ' ) .data ( 'large-image-url ' ) , magnifiersize : [ $ (... | PanoJS failing due to missing method which is n't missing |
JS | I am trying to draw an annulus sector in QML using the Canvas object.First , I have written the javascript code , and I have verified that it is correct by executing it in a browser.Here it is : Here you can run the code above.The output is this : Next , I moved the same code into a Canvas object in Qml.See here the ma... | var can = document.getElementById ( 'myCanvas ' ) ; var ctx=can.getContext ( `` 2d '' ) ; var center = { x : can.width / 2 , y : can.height / 2 } ; var minRad = 100 ; var maxRad = 250 ; var startAngle = toRad ( 290 ) ; var endAngle = toRad ( 310 ) ; drawAxis ( ) ; drawSector ( ) ; function drawSector ( ) { var p1 = { x... | QML Canvas : different behaviour in rendering |
JS | I have a small application that reads tweets and tries to match keywords and I noticed this strange behaviour with a particular string : Now the value of lowercase is : the νіkе dunk ніgh ѕβ 'uglу ѕwеаtеr ' іѕ nоw аvаіlаblе http : //swoo.sh/ihvatlSo it seems like the string is in a weird format , I double checke... | var text = `` The Νіkе Dunk Ніgh ЅΒ 'Uglу Ѕwеаtеr ' іѕ nоw аvаіlаblе http : //swoo.sh/IHVaTL '' ; var lowercase = text.toLowerCase ( ) text.charAt ( 4 ) > '' N '' text.charCodeAt ( 5 ) > 925 ' N'.charCodeAt ( 0 ) > 78 | Javascript toLowerCase strange behaviour |
JS | I am iterating over all the text node in an html document in order to surround some words with a specific span . Changing the nodeValue does n't allow me to insert html . The span is escaped to be shown in plain text and I do not want that.Here is what I have so far : | var elements = document.getElementsByTagName ( '* ' ) ; for ( var i = 0 ; i < elements.length ; i++ ) { var element = elements [ i ] ; for ( var j = 0 ; j < element.childNodes.length ; j++ ) { var node = element.childNodes [ j ] ; if ( node.nodeType === Node.TEXT_NODE ) { node.nodeValue = node.nodeValue.replace ( /Ques... | How to wrap part of all text_node nodeValue in an html element ? |
JS | So I have someone else 's old code that I am trying to restore . I am not too familiar with jQuery , but what does the @ operator specify ? The code is : I am using jQuery 1.3 and it 's throwing an `` uncaught exception : Syntax error , unrecognized expression : [ @ name=button_format ] '' error . Is there a compatibil... | v_button_format = $ ( ' # ' + v_form_id ) .find ( 'input [ @ name=button_format ] ' ) .val ( ) ; v_content_type = $ ( ' # ' + v_form_id ) .find ( 'input [ @ name=content_type ] ' ) .val ( ) ; | jQuery @ operator ? |
JS | I am developing a web page with JavaScript and HTML . I am use jQuery and I must highlight a selected dates . I have that array : My question is , how I can add an element in that array ? I tried a lot of things and I dont know how . And another question , what is the name of that kind of array ? EDIT : I see one thing... | var events = [ { Title : `` Five K for charity '' , Date : new Date ( `` 02/13/2013 '' ) , dir : `` http : //www.google.es '' } , { Title : `` Dinner '' , Date : new Date ( `` 02/25/2013 '' ) } , { Title : `` Meeting with manager '' , Date : new Date ( `` 03/01/2013 '' ) } ] ; Wed Feb 13 2013 00:00:00 GMT+0100 ( Hora d... | Javascript and tipped arrays |
JS | I 'd like to generate some specific style where on the left side there is an image ( icon ) and next to the icon theres some kind of description ( plain text ) . So this is what I got so far : As you can see it 's working quite fine but the second elem ( div ) with the long text is generating a line break what causes m... | .elem { margin-left : 7 % ; position : relative ; width : 100 % ; } .text { display : inline ; vertical-align : middle ; } .img { width : 5 % ; vertical-align : middle ; } < div class= '' elem '' > < img class= '' img '' src= '' https : //d30y9cdsu7xlg0.cloudfront.net/png/172871-200.png '' / > < span class= '' text '' ... | Special indent text next to image |
JS | I 'm building a popup with 3 buttons ! Each button needs to set a cookie but with different expiry time/date . I 'm using jquery.cookie for this ! 1 button is more a session cookie . So when clicking this button the popup needs to dissapear and shown again when I start a new browser screen . So NOT when I open a page i... | $ ( document ) .ready ( function ( ) { var my_cookie = $ .cookie ( 'regNewsletter ' ) ; if ( ! my_cookie ) { setTimeout ( function ( ) { $ ( ' # newsletter ' ) .modal ( 'show ' ) ; } , 1000 ) ; } $ ( `` .close -- btn '' ) .on ( `` click '' , function ( ) { $ .cookie ( 'regNewsletter ' , true , { path : '/ ' , domain : ... | Threeway cookie |
JS | I have a Rickshaw Graph with two lines.I need Rickshaw.Graph.RangeSlider.Preview and Rickshaw.Graph.HoverDetail : http : //jsfiddle.net/nsams/1jfswzp5/3/My IssueMy issue is now that the Hover is shown at an invalid position : What I have found out so far : Removing the RangeSlider.Preview fixes the problemChanging the ... | var graph = new Rickshaw.Graph ( { element : document.getElementById ( 'chart ' ) , renderer : 'line ' , width : 400 , height : 300 , offset : 'value ' , series : [ { name : 'foo ' , data : seriesData.shift ( ) , color : 'rgba ( 255 , 0 , 0 , 0.4 ) ' } , { name : 'bar ' , data : seriesData.shift ( ) , color : 'rgba ( 2... | Rickshaw : HoverDetail at incorrect position when using line renderer plus RangeSlider.Preview |
JS | Is there a significant difference if I construct a jQuery object around an element once or many times ? For instance : versus : I know there are other ways to write this that might sidestep the issue , but my question is about whether I should work to do $ ( el ) just once , or if it truly is irrelevant . The example i... | var jEl = $ ( el ) ; $ .each ( myArray , function ( ) { jEl.addClass ( this ) ; } $ .each ( myArray , function ( ) { $ ( el ) .addClass ( this ) ; } | Is there a performance impact to using the jQuery $ ( ) operator many times ? |
JS | If I create a custom HTML page in Rally with straight HTML and a link to a story to open in another window , clicking the link takes me to the details page of the story properly . But if I wrap the same HTML in the SDK2 , I get sent to an almost blank page -- only the dark blue top bit of the Rally page shows.This work... | < html > < head > < /head > < body > < a target= '' _blank '' href= '' https : //rally1.rallydev.com/ # /9805917202ud/detail/userstory/10746587690 '' > US35 < /a > < /body > < /html > < ! DOCTYPE html > < html > < head > < title > test < /title > < script type= '' text/javascript '' src= '' /apps/2.0p5/sdk.js '' > < /s... | Using Rally SDK2 seems to have trouble with opening a new window/tab with a _blank tag |
JS | Python 's locals ( ) function , when called within the scope of a function , returns a dictionary whose key-value pairs are the names and values of the function 's local variables . For example : Does JavaScript have anything like this ? | def menu ( ) : spam = 3 ham = 9 eggs = 5 return locals ( ) print menu ( ) # { 'eggs ' : 5 , 'ham ' : 9 , 'spam ' : 3 } | Equivalent of Python 's locals ( ) ? |
JS | I am currently trying to parse a JSON with JavaScript . My issue is that I 'd like the output to look like this : However it just does not work and I do n't know how to achieve that . This is the object deserialized from the JSON response : This is my .js file : This is in my HTML fileAny help would be appreciated as I... | < li > AppName1 < /li > < li > AppName2 < /li > < ! -- and so on ... -- > { `` data '' : [ { `` AppId '' : 1 , `` AppName '' : `` AppName1 '' , `` AppSize '' : `` 2.1 '' } , { `` AppId '' : 2 , `` AppName '' : `` AppName2 '' , `` AppSize '' : `` '' } ] } var xmlhttp = new XMLHttpRequest ( ) ; xmlhttp.onreadystatechange... | Parse JSON foreach with JS , shows HTML list |
JS | I noticed that my Javascript bookmarklet was failing on certain sites like Google Reader and Google search results pages ( and randomly on some non-Google sites ) . Looking at the console , I could see that , for these pages , clicking the bookmarklet did not append elements to the head/body like it normally did , but ... | < html > < head > < /head > < body > < /body > < /html > | Javascript bookmarklet fails on certain sites , creates ghostly new < html > page |
JS | I am new to jQuery and am teaching myself as I go but am struggling to figure out how to indicate that on up scroll the white navigation background moves up to show the white navigation text on panel 1 ? bartaile.com is what I am using as inspiration & the changes I 'm making to bartaile 's navigation are -- - > after ... | var lastScrollTop = 0 ; $ ( window ) .on ( 'scroll ' , function ( ) { var header = $ ( '.header ' ) ; var stage0 = $ ( '.stage-0 ' ) ; var scrollTop = $ ( window ) .scrollTop ( ) ; if ( scrollTop > lastScrollTop ) { // down scroll if ( scrollTop > stage0.offset ( ) .top + stage0.height ( ) ) { header.addClass ( 'hide '... | Navigation transition |
JS | Fetch is the new Promise-based API for making network requests : This makes sense to me - when we initiate a network call , we return a Promise which lets our thread carry on with other business . When the response is available , the code inside the Promise executes . However , if I 'm interested in the payload of the ... | fetch ( 'https : //www.everythingisawesome.com/ ' ) .then ( response = > console.log ( 'status : ' , response.status ) ) ; fetch ( 'https : //www.everythingisawesome.com/ ' ) //IO bound .then ( response = > response.json ( ) ) ; //We now have the response , so this operation is CPU bound - is n't it ? .then ( entity = ... | Why are these fetch methods asynchronous ? |
JS | I need to run generator async ( I need to have result in console 1,2,3,4,5 cause now I have 4,1,2,3,5 ) any one can help me ? I need run task and wait when previous task is finished before it run next task . I need to use ( if possible : only ) generators ( or generator + promise ? ) Here my code | /*jshint esnext : true */function show ( msg ) { var _msg = msg ; setTimeout ( function ( ) { console.log ( _msg ) ; } , 2000 ) ; } function show2 ( msg ) { console.log ( msg ) ; } var stack = [ ] ; // add some function to stackstack.push ( function ( ) { show ( 1 ) ; } ) ; stack.push ( function ( ) { show ( 2 ) ; } ) ... | Javascript ES6 generator async |
JS | So I have a modal that has a form . When the 'submit ' button is pressed on that modal , I want another modal to be executed . How do I do that ? This is my first modal - views/shared/_upload_video_popup.html.erb : That is executed by this button : When the f.button : submit , `` Add Video '' , id : `` video-submit '' ... | < div id= '' overlay '' > & nbsp ; < /div > < div class= '' popup '' id= '' add-video-step-1 '' > < div class= '' titles clearfix '' > < h2 > Upload a Video < /h2 > < p > < i > Step 1 of 2 - TEST < /i > < /p > < /div > < div class= '' content '' > < % if @ family_tree % > < % = simple_form_for ( [ @ family_tree , @ vid... | How do I fire another modal when a button is pressed on the current modal ? |
JS | I am developing HTML5 boardgame with Javascript.How I can find ( recursively ) where I can get with dice number I get ? Example : I get 4 from dice and my position is 11 . Possible places are 22 , 15 and 7.I have tried this ; it works great , but returns wrong numbers into console : | $ ( function ( ) { // Initialize var pos = 11 ; var dice = 4 ; var diceMax = 4 ; var postPlaces = [ ] ; var places = [ ] ; // List of gameboard 's numbers : from where to where numbers = { 1 : [ 25,21,2 ] , 2 : [ 1,3 ] , 3 : [ 2,4 ] , 4 : [ 3,5 ] , 5 : [ 4,6 ] , 6 : [ 5,19,7 ] , 7 : [ 6,8 ] , 8 : [ 7,9 ] , 9 : [ 10,8 ]... | Javascript board game - Finding possible places on board |
JS | I have a number of items that get their data from a Json object and populate it using angular.And whenever I load the form , I get something like this in my console : I can get the values to appear just fine , but I ca n't seem to get rid of the very first option . I do n't mind the select box showing the very first el... | < select ng-model= '' MyCtrl.cargoList '' > < option ng-repeat= '' cargo in MyCtrl.cargoList '' > { { cargo.name } } < /option > < /select > < select ng-model= '' MyCtrl.cargoList '' > < option value= '' ? object:25 `` ? > < /option > < option value= '' '' > Gloves < /option > < option value= '' '' > Jacket < /option >... | Get rid of blank entry in select tag |
JS | Code below got error Maximum call stack size exceeded as expected.I expect this exceeded the maximum call stack , too.However , it runs , why ? Result : print till a number and stop , but no errors.I 'm using NodeJs 10 on Windows 10UpdateChrome got error | function recurrent ( i = 0 ) { recurrent ( ++i ) } recurrent ( ) function recurrent ( i = 0 ) { console.log ( i ) recurrent ( ++i ) } recurrent ( ) ... 10815108161081710818108191082010821108221082310824 | console.log avoid maximum call stack |
JS | I was going through the mongoose docs when I Stumbled upon the line saying Mongoose queries are not promises . They have a .then ( ) function for co and async/await as a convenience . If you need a fully-fledged promise , use the .exec ( ) function.With this example Now , I did n't get what they meant when they said fu... | var query = Band.findOne ( { name : `` Guns N ' Roses '' } ) ; assert.ok ( ! ( query instanceof Promise ) ) ; // A query is not a fully-fledged promise , but it does have a ` .then ( ) ` .query.then ( function ( doc ) { // use doc } ) ; // ` .exec ( ) ` gives you a fully-fledged promisevar promise = query.exec ( ) ; as... | what is fully-fledged promise |
JS | Why is the str [ 3 ] version so much slower , apparently ? http : //jsperf.com/charat-ckEdit : for me , str [ 3 ] is 80 % slower on Chrome 28.0.1500.71 Ubuntu 13.04 . | var str = 'Hello ' ; str.charAt ( 3 ) ; str [ 3 ] ; | str.charAt ( 5 ) vs str [ 5 ] in Javascript |
JS | after running this script , I got UnhandledPromiseRejectionWarning : Error : Firefox revision is not downloaded . Run `` npm install '' or `` yarn install '' in the console . how to fix it ? | const playwright = require ( `` playwright '' ) ; ( async ( ) = > { const browsers = [ `` chromium '' , `` firefox '' , `` webkit '' ] ; for ( const browserType of browsers ) { const browser = await playwright [ browserType ] .launch ( { args : [ ' -- no-sandbox ' ] } ) ; const context = await browser.newContext ( ) ; ... | Playwright Error : Firefox revision is not downloaded . Run `` npm install '' or `` yarn install '' |
JS | I have a task to highlight the menu as selected while loading the page . For that I have the following code : But when I select the second menu , it 's refreshed and missing the selection.HTML : How can I solve this problem ? | $ ( '.menuHeader ' ) .each ( function ( ) { $ ( this ) .attr ( 'id ' , 'menu ' + ( $ ( this ) .index ( ) + 1 ) ) ; $ ( this ) .val ( $ ( this ) .index ( ) + 1 ) ; // Set the dynamic ids for links $ ( this ) .find ( ' a ' ) .attr ( 'id ' , 'link ' + ( $ ( this ) .index ( ) + 1 ) ) ; //alert ( 'New ID : ' + $ ( this ) .f... | How to apply CSS for the menu while selecting ? |
JS | I 'm using two techniques to create a wavetable synthesizer sound :1 - Loop an AudioBufferSourceNode which contains a single waveform cycle 2 - Create a PeriodicWave and provide it with fourier coefficients ( using coefficients found on the web , i.e . ( 0,1 ) for a sine wave , ( 0 , .1 , .4 , .6 , ... ) for more compl... | // Load a single cycle short wave file , then : audioContext.decodeAudioData ( audioData , function ( buffer ) { source.buffer = buffer ; source.loop = true ; } , var wave = ac.createPeriodicWave ( real , imag ) ; OscillatorNode.setPeriodicWave ( wave ) ; | Web Audio API - difference between PeriodicWave and looping AudioBufferSourceNode to achieve a wavetable ? |
JS | I have an Array of 16 billiard balls in JS and want to move each ball smoothly with its direction and speed.For that I set up a timer , calling UpdateThis ( ) every 42ms ( for 24 fps ) .The problem is that UpdateThis ( ) takes 53ms as firebug states.Now UpdateThis iterates over every ball and calls UpdateBall ( ball ) ... | function UpdateBall ( ball ) { if ( ball.direction.x ! = 0 & & ball.direction.y ! = 0 ) { //ball moving ! for ( var i = 0 ; i < balls.length ; i++ ) { //CheckCollision ( ball , balls [ i ] ) ; //even without this it takes 53 ms ! } var ps = VAdd ( ball.position , VMul ( ball.direction , ball.speed ) ) ; //Multiply Dire... | How to speed up this moving algorithm ? In Javascript |
JS | I have the following function a file @ /lang/index.js : I would like to hot-reload the modules imported by this function . I 've tried a several different variations of module.hot.accept ( ) but without success.Here 's my hot reload code at the end of the same file that does n't work : Any thoughts ? I would like to ho... | async function fetchMessages ( locale ) { const module = await import ( /* webpackChunkName : `` lang/ [ request ] '' , webpackExclude : /index/ */ ` @ /lang/ $ { locale } ` ) return module.default } if ( process.env.NODE_ENV ! == `` production '' & & module.hot ) { module.hot.accept ( [ `` ./en-US '' ] , ( ) = > { con... | How do I hot reload a module wrapped in a native import context ? |
JS | how do I find what index of the value `` banana '' is ? ( which , of course , is `` 1 '' ) .thanks | var fruits = [ 'apple ' , 'banana ' , 'orange ' ] ; | How do I get the index of an item in an array ? |
JS | I 'm using two $ watches on my controller that are supposed to take an eye at these two objects : Two charts ( from the Charts.js and angular-charts plugins ) read data from them . I 've put the charts in custom directives that receive the data from an attribute , and they 're working properly . The problem is , that I... | $ scope.gastos = { name : `` Gastos mensuales '' , data : [ 0,0,0,0,0,0,0,0,0,0,0,0 ] , labels : [ `` Enero '' , `` Febrero '' , `` Marzo '' , `` Abril '' , `` Mayo '' , `` Junio '' , `` Julio '' , `` Agosto '' , `` Septiembre '' , `` Octubre '' , `` Noviembre '' , `` Diciembre '' ] } ; $ scope.ganancias = { name : `` ... | Angular $ watch not working |
JS | I 'll start with the problem : I 'm changing the content of an object literal . ( changing the properties values ) The Firebug console ( at first clicks ) shows the correct values . But after a while , it get stuck on a specific value and stop from changing . ( notice : the stringify representation of the object - Alwa... | var obj = { getData : function ( ) { obj.CountryId = $ ( `` .ddlCountry '' ) .val ( ) || `` '' ; obj.CountryText = $ ( `` .ddlCountry : selected '' ) .text ( ) || `` '' ; obj.StateId = $ ( `` .ddlState : visible '' ) .val ( ) || `` '' ; obj.StateText = $ ( `` .ddlState : visible : selected '' ) .text ( ) || `` '' ; obj... | Cached object in console ? |
JS | I do a lot of full-stack JS work , and I generally follow an approach like this when creating a file with encapsulated logic : I 've also used classes occasionally , which essentially provide the same structure , except the module state would be inside the class as an instance variable , and possibly static variables f... | export const SOME_KEY_TO_STATE = 'some-key ' ; export const ANOTHER_KEY_TO_STATE = 'another-key ' ; let moduleState = { } ; export function modifyState ( someArg ) { // ... do some logic // ... perhaps derive some new value based off of logic const newValue = derivedNewValue ; moduleState [ someKey ] = newValue ; } exp... | is there a benefit to using classes in js vs creating standalone functions |
JS | Some URLs in my single-page-app ( SPA ) contain sensitive information like an access token , user information , etc . Examples : I see that hotjar allows suppressing DOM elements and images from tracked data . Is it possible to hide params in URL or at least disable tracking for some pages ? | /callback # access_token=HBVYTU2Rugv3gUbvgIUY/ ? email=username @ example.com | How to prevent tracking sensitive data in URLs ? |
JS | Consider this snippet : https : //jsfiddle.net/1kqLofq4/2/I 'm curious about why changing hash is n't adjusting length of history but using history.back ( ) is required to revert that change of hash ? I have tested this scenario with Firefox 46 and Chrome 49 . Output is always similar to this : I 've tried searching fo... | console.log ( `` 1st '' , history.length ) ; location.hash = location.hash + `` some-value '' ; console.log ( `` 2nd '' , history.length ) ; setTimeout ( function ( ) { console.log ( `` 3rd '' , history.length ) ; history.back ( ) ; console.log ( `` 4th '' , history.length ) ; } , 1000 ) ; 1st 172nd 173rd 174th 17 | Why is changing hash not affecting length of history ? |
JS | So , I was told that passing around the request and or response variable in nodeJS is `` bad practice '' . But this means that most of your code has to be in the server.js file , making it cluttered and kind of ugly.How can you modularize your nodejs server , passing around req/res appropriately and be able to organize... | app.io.route ( `` disconnect '' , function ( req , res ) { < -- - these params db.query ( `` UPDATE player_data SET online=0 WHERE id= '' +mysql.escape ( req.session.user ) ) ; req.io.broadcast ( `` event '' , { msg : req.session.username+ '' has logged out ! `` } ) ; app.io.broadcast ( `` reloadXY '' ) ; } ) ; | NodeJS Modulization |
JS | I am creating a slideshow that use Transition objects to transition slides : Each of the methods correspond to how the slide should behave should it be transitioning in from the right , out to the right , in from the left , and out to the left . All well and good when the Transition is acting upon slides : However , as... | function Transition ( slide , settings ) { this.slide = slide ; this.el = slide.el ; this.settings = settings ; this.duration = ( this.settings [ 'transitionSpeed ' ] / 1000 ) + 's ' ; this.endAnimation = null ; } Transition.prototype.inRight = function ( callback ) { callback ( ) ; } Transition.prototype.outRight = fu... | Sealed methods in javascript |
JS | I have implemented NVD3 Charts in Angular 4. written an on Click event inside a callback function , on click of the chart I am trying to navigate to another component but I am unable to navigate.Code : } I am getting this error in Console . Could not able find the component reference to redirect.Awaiting Suggestions . ... | import { Router } from ' @ angular/router ' ; export class MyNewComponentComponent implements OnInit { constructor ( public router : Router ) { } this.options = { chart : { type : 'discreteBarChart ' , height : 450 , margin : { top : 20 , right : 20 , bottom : 50 , left : 55 } , x : function ( d ) { return d.label ; } ... | How to navigate the component from NVD3 Callback in Angular 4 ? |
JS | When I run the following code I get told , that talk is not a function . Why ? | function cat ( name ) { talk = function ( ) { alert ( `` say meeow ! '' ) } } cat ( `` felix '' ) ; cat.talk ( ) | Not a function ? |
JS | Each time when I call Element.getClientRects ( ) , it returns a collection of only one DOMRect object.When does Element.getClientRects ( ) return a collection of multiple DOMRect objects ? | function handleClick ( ) { console.log ( event.target.getClientRects ( ) ) } < ul style= '' border : 1px solid black ; '' onclick= '' handleClick ( ) '' > < li > Click the text to see in console < /li > < /ul > | When does Element.getClientRects ( ) return a collection of multiple objects ? |
JS | I 'm using GWT and the GWT GoogleMaps API ( v3.8.0 ) . I have everything up and running perfectly.However , I 'd like to disable a few of the default features that come with GoogleMaps , such as street names , the ability to click on restaurants , etc . Basically I 'd like a very barebones map layer that I add my own c... | package com.test.client ; import com.google.gwt.ajaxloader.client.AjaxLoader ; import com.google.gwt.ajaxloader.client.AjaxLoader.AjaxLoaderOptions ; import com.google.gwt.core.client.EntryPoint ; import com.google.gwt.core.client.JsArray ; import com.google.gwt.dom.client.Document ; import com.google.maps.gwt.client.G... | GWT GoogleMaps Hide Default Layers Using Styles |
JS | I can easily traverse the following from left to right , but I 'm having a lot of trouble ( 2 days in , and no progress ) getting a formula to traverse it from top right & bottom right.Basically , I 'm looking for a formula which can retrieve the following values : The only part that I could get working was the topRigh... | let topRight = [ [ h [ 2 ] [ 4 ] , h [ 3 ] [ 3 ] , h [ 4 ] [ 2 ] ] , [ h [ 1 ] [ 3 ] , h [ 2 ] [ 3 ] , h [ 3 ] [ 2 ] , h [ 4 ] [ 1 ] ] , [ h [ 0 ] [ 2 ] , h [ 1 ] [ 2 ] , h [ 2 ] [ 2 ] , h [ 3 ] [ 1 ] , h [ 4 ] [ 0 ] ] , [ h [ 0 ] [ 1 ] , h [ 1 ] [ 1 ] , h [ 2 ] [ 1 ] , h [ 3 ] [ 0 ] ] , [ h [ 0 ] [ 0 ] , h [ 1 ] [ 0 ]... | Traverse a Hexagon |
JS | What I 'm trying to achieve is adding a text-shadow to an emoji with the text-shadow color being the most prominent color in the emoji.I know there are JavaScript libraries that identify the most prominent color in images , but since the emoji is technically text I 'm not sure how I 'd do it or even if it 's possible a... | .emoji { text-shadow : 0px 0px 20px rgba ( 54 , 169 , 230 , 0.65 ) ; padding : 3px 6px ; font-size : 24px ; } < span class= '' emoji '' > < /span > | Is it possible to get the majority color of an emoji ? |
JS | I was reading through the source for the _.isFunction ( ) function and saw this line : and I do n't understand why it 's there . /./ is a regex that always seem to have the type object . Why would n't _.isFunction be redefined if /./ type was a function ? | if ( typeof ( /./ ) ! == 'function ' ) { | why is typeof ( /./ ) ! == 'function ' used in underscore |
JS | Here is the situation : CSS ( in < head > section ) : When i use standard fonts ( Arial for example ) everything fine ( .width ( ) returning same result in both cases ) Is there any workaround different than setTimeout to get proper .width ( ) value and keep custom fonts ? | $ ( document ) .ready ( function ( ) { // this will return different result alert ( $ ( ' # foo ' ) .width ( ) ) ; // than this ! ! ! setTimeout ( function ( ) { alert ( $ ( ' # foo ' ) .width ( ) ) ; } , 1000 ) ; } ) ; < link href='http : //fonts.googleapis.com/css ? family=Headland+One ' rel='stylesheet ' type='text/... | $ .width ( ) returns different results when using custom fonts |
JS | I 'm learning javascript by reading `` Eloquent Javascript '' and am confused by the `` Closures '' section in chapter 3 ( Functions ) .In previous sections I learned about arrow functions , and how they can be used as anonymous functions . My initial thoughts were that this is an anonymous function example and I am si... | function wrapValue ( n ) { let local = n ; return ( ) = > local ; } let wrap1 = wrapValue ( 1 ) ; let wrap2 = wrapValue ( 2 ) ; console.log ( wrap1 ( ) ) ; // → 1console.log ( wrap2 ( ) ) ; // → 2 | What does `` return ( ) = > local ; '' do in this closure ? |
JS | Good day to you all , I 've encountered a frustrating issue that seems to happens only in Chrome.Firefox and Safari seem to handle this as expected , whereas Chrome is casting string-ish JSON keys to integers.jQuery 's parseJSON method has the same behaviour ( I 'm assuming it relies on the browser 's JSON.parse method... | var response = ' { `` 01 '' : '' January '' , '' 02 '' : '' February '' } ' , months = JSON.parse ( response ) ; console.log ( months [ '02 ' ] ) // undefined in Chrome ( my version is 24.0.1312.5 beta ) console.log ( months [ 2 ] ) // `` February '' | How to prevent automatic JSON key type-casting |
JS | The code sample is - When I run this code in nodejs , I get the following output : But the same code , with global changed to window in Chrome/Firefox prints aaa and the window object , which is what this MDN doc says and which is what I expect.I was under the impression that nodejs and Chrome both use Google 's v8 JS ... | global.a = 'aaa ' ; const obj = { a : ' a ' , desc ( ) { console.log ( this ) ; console.log ( this.a ) ; } } setTimeout ( obj.desc , 2000 ) Timeout { _called : true , _idleTimeout : 2000 , _idlePrev : null , _idleNext : null , _idleStart : 79 , _onTimeout : [ Function : desc ] , _timerArgs : undefined , _repeat : null ... | Different behaviour of setTimeout in nodejs and Chrome |
JS | I wrote a little chat plugin that i 'll need to use on my site . It works with a simple structure in HTML , like this : There 's a 'click ' bound event on that Span element , of course . Then , when the user inserts a message and clicks on the `` Send '' span element , there 's a Javascript function with calls an Ajax ... | < div id= '' div_chat '' > < ul id= '' ul_chat '' > < /ul > < /div > < div id= '' div_inputchatline '' > < input type= '' text '' id= '' input_chatline '' name= '' input_chatline '' value= '' '' > < span id= '' span_sendchatline '' > Send < /span > < /div > function function_write_newchatline ( ) { var chatline = $ ( '... | Chrome issue - chat lines return multiple times |
JS | I have an application in PHP and JS . When I EVAL the json encoded PHP array the array sort changes . For example , if I have an array in PHP like this : When I print the array in console , the elements does n't have the same position . Do you know how can this happens ? UPDATE Thanks for the answers but I want to keep... | < ? php $ array = [ 148 = > 'Plane ' , 149 = > 'Car ' ] ; ? > < script > var array = eval ( < ? php echo json_encode ( $ array ) ? > ) ; < /script > [ 148 = > object , 155 = > object , 133 = > object ] | Does js EVAL function change position of elements ? |
JS | Scroll down for the getById.getByClassName vs. qSA comparison ! If we wanted to select all elements of class `` bar '' which are inside the element with the ID `` foo '' , we could write this : or this : There are of course other methods to achieve this , but for the sake of this question , let 's compare only these tw... | $ ( ' # foo .bar ' ) $ ( '.bar ' , ' # foo ' ) ( function ( ) { var i ; console.time ( 'test1 ' ) ; for ( i = 0 ; i < 100 ; i++ ) { $ ( ' # question-mini-list .tags ' ) ; } console.timeEnd ( 'test1 ' ) ; console.time ( 'test2 ' ) ; for ( i = 0 ; i < 100 ; i++ ) { $ ( '.tags ' , ' # question-mini-list ' ) ; } console.ti... | Comparing the performance of $ ( `` # foo .bar '' ) and $ ( `` .bar '' , `` # foo '' ) |
JS | I am inserting GA snippet in my TypeScript code and seeing this : TypeScript compiler complains that new Date ( ) must be number or any , but not Date.I turned this into this : Which leads to the same result.If the priority is to reduce the size , then I find this even more compact giving the same result : I have no id... | i [ r ] .l = 1 * new Date ( ) ; i [ r ] [ ' l ' ] = new Date ( ) .getTime ( ) ; i [ r ] [ ' l ' ] = +new Date ( ) ; | Why 1 * new Date ( ) instead of new Date ( ) .getTime ( ) in GA snippet ? |
JS | I am trying to wrap letters around a circle border of 4 divs . I have figured out 'How ' to accomplish this but i am falling short understanding how to position my letters to wrap counterclockwise and from top to bottom . Below is my snippet . I want the top of the letters to ride the inside border of the bottom two di... | // begin jQuery -- $ ( document ) .ready ( function ( $ ) { var audio = new Audio ( 'http : //soundbible.com/grab.php ? id=1377 & type=mp3 ' ) ; function beep ( ) { audio.play ( ) ; } var c = 0 ; var resumeT = 0 ; var t ; var timer_is_on = 0 ; $ ( ' # resume ' ) .hide ( ) ; var pomodoros = 0 ; // Convert given number t... | Letter wrapping around a circle |
JS | I have a method that will let me select the prototype object when creating a new object ( copied from `` Javascript : The Good Parts '' book ) : Now say , I have an object : And I create a new object based on this object , using the `` Create '' method : I can then add a property to car and it will dynamically get adde... | Object.create = function ( o ) { var F = function ( ) { } ; F.prototype=o ; return new F ( ) ; } var car = { model : `` Nissan '' } ; var car1 = Object.create ( car ) ; car.year=2011 ; // Gets added to `` car '' ... alert ( car1.year ) ; // ... Is also avaialable to car1 Object.prototype.originCountry = `` Japan '' ; a... | Javascript prototype behavior |
JS | While I know that capturing keys due to the e.keyCode vs e.charCode is not trivial , I thought that jQuery would pretty much be able to normalize most of those inconsistencies.However while answering this question I found out that the character # seems to have very inconsistent keyCodes ( and of course this is true for... | $ ( 'input ' ) .keydown ( function ( e ) { if ( e.which == 191 || e.which == 163 || e.which == 222 ) { // hope you got the right key e.preventDefault ( ) ; } } ) ; | consistent keyCode for ` # ` |
JS | I created an image slider that ends on one image , but now I 'd like to take it a step further and make it loop.Here is my code in the head tagand here is where it is implemented in the body codeCould I turn it into a function and then loop it ? Can I get any guidance on that ? Thank you very much | < style > # picOne , # picTwo , # picThree , # picFour , # picFive { position : absolute ; display : none ; } # pics { width:500px ; height:332px ; } < /style > < script src= '' http : //code.jquery.com/jquery-1.4.4.min.js '' type= '' text/javascript '' > < /script > < script type= '' text/javascript '' > $ ( document ... | How to make my script loop |
JS | I am trying to create recurrence every 3 and 6 months using the later.js ( https : //github.com/bunkat/later ) .This is my code This gives 3 months recurrence starting from the current month , but I want the recurrence to start from the scheduled_date . When I add starting On to the code Recurrence is staring only afte... | // My value.scheduled_date is 2018-09-06var d = new Date ( value.scheduled_date ) ; var day = d.getDate ( ) ; // month count will be -1 as it starts from 0var month = d.getMonth ( ) ; var year = d.getFullYear ( ) ; var recurSched = later.parse.recur ( ) .on ( day ) .dayOfMonth ( ) .every ( 3 ) .month ( ) ; var schedule... | Every 3 and 6 Months Recurrence on later.js stating from a particular date |
JS | I have this structure of html tableand how it 's look likebut should be as : my js code add codepen reference codepen.io/paulch/pen/MzQYjg | < thead > < tr > < th rowspan= '' 2 '' > Type < /th > < th rowspan= '' 2 '' > Name < /th > < th rowspan= '' 2 '' > Iteration ID < /th > < th colspan= '' 2 '' > Script < /th > < th rowspan= '' 2 '' > Action < /th > < /tr > < tr > < th > Init < /th > < th > Post < /th > < /tr > < /thead > $ ( document ) .ready ( function... | Issue with Tabulator js library working with Column Grouping properties |
JS | I am trying to do some image manipulation via gm in collectionFS , because I need to read a stream and write it back to the same file , I have to use a temp-file - like shown below.I want to check if the image is wider than 1000px . In this case it should be re-sized to 1000px.Unfortunately this does n't work , as I go... | var fs = Npm.require ( 'fs ' ) , file = Images.findOne ( { _id : fileId } ) , read = file.createReadStream ( 'public ' ) , filename = '/tmp/gm_ ' + Date.now ( ) , temp = fs.createWriteStream ( filename ) ; if ( method == 'resize ' ) { // resize to 1000px , if image is bigger gmread = gm ( read ) ; gmread.size ( functio... | gm : resize image if it is wider than 1000px |
JS | I 'm still fighting with ambiguous grammar of Qt 's qmake.Now I ca n't find a way to describe function arguments that can contain parenthesis ( e.g . regex ) : I 've tried to describe function call like this : How do I add support for embedded parenthesis WITHOUT quotes/double quotes in such grammar ? How do I distingu... | functionName ( arg1 , `` arg2 '' , ^ ( arg3 ) + $ ) FunctionCall = Identifier space* `` ( `` space* FunctionArgumentList ? space* `` ) '' space* eol*FunctionArgumentList = FunctionArgumentString ( ( space* `` , '' space* FunctionArgumentString ) * / ( blank* FunctionArgumentString ) * ) FunctionArgumentString = Replace... | How to describe function arguments in PEG grammar |
JS | In the minimal example below , the replacement of old content is deferred by setTimeout to give the user time to finish viewing it . In the meantime , new content is being prepared so as to avoid blocking the user interface during a potentially expensive task.My concern with this approach is that it does not seem to ha... | var div = document.getElementById ( 'wrapper ' ) ; var newContent = document.createElement ( 'ul ' ) ; setTimeout ( function ( ) { var header = div.firstElementChild ; header.innerHTML = 'New Content ' ; header.nextElementSibling.remove ( ) ; div.appendChild ( newContent ) ; } , 2000 ) ; // Make new content while we wa... | Execute code that deferred function depends on while waiting |
JS | I can claim that 'this ' keyword is the most confusing part of Javascript for those who comes from languages like C # .I have read a lot about this on the internet and on StackOverflow too . like here and here.I know that 'this ' keyword will be bound to the context . and in constructor function it will be bound to the... | function sayHi ( name ) { var tt = name ; return { ss : tt , work : function ( anotherName ) { alert ( `` hiiiii `` + anotherName ) ; } } ; } //this method invocation has no effect at all right nowsayHi ( `` John '' ) ; var hi2 = new sayHi ( `` wallace '' ) ; hi2.work ( `` May '' ) ; alert ( hi2.ss ) ; function sayHi (... | confusion about the 'this ' keyword in Javascript |
JS | For as long as I have been writing for the canvas , I 've always done the following : Lately though , I have frequently seen it done this way : While I can of course see benefits for doing it my way , ( mainly , if there 's a bug it wo n't continue to call more frames ) I have been unable to find any benefits for calli... | function animate ( ) { //do stuff in the animation requestAnimationFrame ( animate ) ; } function animate ( ) { requestAnimationFrame ( ) ; //do stuff in the animation } | Why do you put requestAnimationFrame before the function body ? |
JS | The problem is very simple , I have a function from 'Javascript Allonge ' book , and having a hard time in understanding it.The function is called even , and it 's as follows : it checks whether the number is even or not , but I do not understand how . It calls itself recursively , and technically , always reaches zero... | var even = function ( num ) { return ( num === 0 ) || ! ( even ( num -1 ) ) ; } | Recursive even function issue with understanding ( Javascript ) |
JS | I recently posted an answer to a question when I made an observation about key 's when returned from an array.I already know that keys must be unique among sibling components . This is stated in the official React documentation , here : Keys used within arrays should be unique among their siblings . However they do n't... | class MyApp extends React.Component { renderArray = ( ) = > { return [ < p key= { 0 } > Foo < /p > , < p key= { 1 } > Bar < /p > , < p key= { 2 } > Baz < /p > ] ; } render ( ) { return ( < div > { this.renderArray ( ) } { this.renderArray ( ) } { this.renderArray ( ) } < /div > ) ; } } ReactDOM.render ( < MyApp / > , d... | No key collision when returning identical arrays ? |
JS | I 'm often finding myself passing around a lot of parameters from function to function . Looks like this : While I could see that storing these in an object specs would make sense `` visually '' I 'm curious as to the performance implications of creating the object , assinging all the key/val pairs and passing the obje... | ajaxLiveUpdate : function ( bindTo , func , interval , dyn , el , lib_template , locale , what ) { // do sth } | should I pass function parameters encapsuled in an object or one by one if performance matters in Javascript ? |
JS | I 'm quite new to Haskell and ghcjs . I 'm starting with the very first `` Hello , world ! '' program to learn.Here is my Haskell program , copied from GHCJS wiki : I use the command ghcjs -o hello hello.hs to compile it to javascript , and I tried to run it on my Terminal with the command node hello.jsexe/all.js , but... | module Main wheremain = putStrLn `` Hello world ! '' < ! DOCTYPE html > < html > < head > < script language= '' javascript '' src= '' rts.js '' > < /script > < script language= '' javascript '' src= '' lib.js '' > < /script > < script language= '' javascript '' src= '' out.js '' > < /script > < /head > < body > < /body... | Am I using ghcjs correctly ? |
JS | I have absolutely positioned elements with different position.top and height generated from database . All I 'm trying to do is to un-collide these elements by shifting them to the right while adjusting width to fit inside the < body > container.I 'm having an issue applying 'left ' position to the collided elements.I ... | $ ( 'div ' ) .each ( function ( ) { var name = $ ( this ) .text ( ) ; var hits = $ ( this ) .collision ( 'div ' ) .not ( this ) ; // Find colliding elements console.log ( name + ' collides with : ' + hits.length + ' others ' ) ; if ( hits.length > 0 ) { var widthAll = 100 / ( hits.length + 1 ) ; // Shift colliding elem... | Fit colliding elements in the container dynamically |
JS | I need to close a < span > tag before the word `` hello '' and reopen it just after when a button is clicked.Here is a FiddleThis is my code : jQuery : The HTML output I have after clicking .button is : And the output I want is : Why is n't the .join function inserting the < /span > closing tag ? | < span class= '' border '' > border Hello border border < /span > < div > < span class= '' button '' > Style me ! < /span > < /div > $ ( '.button ' ) .click ( function ( ) { $ ( '.border ' ) .each ( function ( ) { var t = $ ( this ) .text ( ) ; var s = t.split ( 'Hello ' ) .join ( ' < /span > Hello < span class= '' bor... | Close and reopen tag around specific word |
JS | Check this jsfiddle separately in Chrome and Firefox : http : //jsfiddle.net/9aE2p/1/Also pasting the same code here : What I am noticing is that hasChildNodes ( ) returns false for Firefox and true for Chrome.If a nodeType is an attribute node , then in Chrome it has a child node which has the actual value.But in Fire... | var xmlStr = ' < ? xml version= '' 1.0 '' encoding= '' UTF-8 '' ? > < abc abc_attr= '' abc_attr_value '' > < abc_child abc_child_attr= '' abc_child_attr_value1 '' / > < abc_child abc_child_attr= '' abc_child_attr_value2 '' / > < /abc > ' ; var parser = new DOMParser ( ) ; var xmlDoc = parser.parseFromString ( xmlStr , ... | hasChildNodes ( ) of attribute nodes return different results for Chrome and Firefox |
JS | I want to pass an argument to a function called using setTimeout . I have found these three options : This shows 2 , undefined , and 1 in Internet Explorer 9.Method 1 : Clearly , I would not like the argument to be changed after passing it ( certainly in the case of simple integers ) .Method 2 : This would be perfect i... | A = 1 ; // Method 1 : closure thingssetTimeout ( function ( ) { whatsA ( A ) ; } , 100 ) ; // Method 2 : third argument ( same result with [ A ] ) setTimeout ( whatsA , 100 , A ) ; // Method 3 : evalsetTimeout ( 'whatsA ( ' + A + ' ) ' , 100 ) ; A = 2 ; function whatsA ( X ) { console.log ( X ) ; } | How can I pass an argument to a function called using setTimeout ? |
JS | I using the following code to add script tag after existing enclosing script tag ( adding new script tag inside html file by code ) ( Script content is helloworldThe html content look like following I want that the second opening script tag will be line after the enclosing script tag ( in the first line ) how can i do ... | return '\n ' + `` < script > \n '' + '\t ' + scriptContent + `` \n < /script > \n '' ; return `` < br / > '' + '' \n '' + '' < script > \n '' + '\t ' + scriptContent + `` \n < /script > \n '' ; ... .ui-resourceroots= '' { 'tdrun ' : './ ' } '' > < /script > < script > alert ( `` test '' ) ; < /script > | add script tag line after the previous script indetend |
JS | I have a need for a variadic version of R.either . After doing some searching around the web , I have not found a solution . R.anyPass would work but it returns a Boolean instead of the original value . Is there already a solution that I have overlooked ? If not , what would be the most optimal way to write a variadic ... | const test = variadicEither ( R.multiply ( 0 ) , R.add ( -1 ) , R.add ( 1 ) , R.add ( 2 ) ) test ( 1 ) // = > 2 | Is there a Variadic Version of either ( R.either ) ? |
JS | I want to get data from server with signalr and update content of React component . Everything is ok. Data is received from the server BUT state of component could not update ( undefined ) . Here is my code : | import React , { Component } from 'react ' ; import { ToastComponent } from ' @ syncfusion/ej2-react-notifications ' ; import * as signalR from ' @ aspnet/signalr ' ; class Notification extends React.Component { constructor ( ) { super ( ... arguments ) ; this.position = { X : 'Right ' , Y : 'Top ' } this.state = { mes... | How to set state of component in Signalr connection.on ( ) |
JS | I 'm trying to make a cursor that leaves a trail of magic dust like in that intro to any Disney film : example . So the way I see it is it 's split into two parts . 1. the trail and 2. similar trail that falls and fades out . So far I have made the basic trail work quite well , the code below is for the falling trail a... | window.addEventListener ( 'mousemove ' , function ( e ) { //trail [ 1 , .9 , .8 , .5 , .25 , .6 , .4 , .3 , .2 ] .forEach ( function ( i ) { var j = ( 1 - i ) * 50 ; var elem = document.createElement ( 'div ' ) ; var size = Math.ceil ( Math.random ( ) * 10 * i ) + 'px ' ; elem.style.position = 'fixed ' ; elem.style.zIn... | Creating a disney dust style cursor trail |
JS | I am using Polymer to play around with the shadow dom . I have what I feel like should be a simple use case that I ca n't quite get working . I want define a `` nav '' container that can contain nav links . I 'd like it to look like the following : The following are the definitions that I created for the two elements (... | < top-nav > < nav-link href= '' # a '' > A < /nav-link > < nav-link href= '' # b '' > B < /nav-link > < nav-link href= '' # c '' > C < /nav-link > < nav-link href= '' # d '' > D < /nav-link > < /top-nav > < polymer-element name= '' top-nav '' noscript > < template > < ul class= '' nav nav-tabs '' > < content > < /conte... | How to Get Shadow Dom to Work With A LIst ? |
JS | I 've come across two different ways to define/name objects and functions in JavaScript that first check for the existence of the name before using it . The issue is , I do n't know which one is better ( from speed and usability standpoints ) and it 's impossible to use the boolean operators in a Google search to figur... | var myNewObject = myNewObject ? myNewObject : function ( ) { // Code goes here . } ; var myNewObject = myNewObject || function ( ) { // Code goes here . } ; | JavaScript object definition conditionals - which is better ? |
JS | so on my website im using google custom search engine , when i search example 'youtub ' not 'youtube'it shows as a suggestion ( Showing results for youtube - Search instead for youtub ) or ( Did you mean : youtube ) so when i click on text youtube , I want to add it on my searchbox , how i can do it ? this is my codese... | < form action= '' '' method= '' GET '' id= '' searchform '' > < input required= '' '' type= '' search '' name= '' q '' id= '' searchbox '' placeholder= '' Search ... '' title= '' Search ... '' enableAutoComplete= '' true '' autofocus/ > < button > < div class= '' Search-Button '' > < img src= '' MYIMGHERE '' class= '' ... | on suggestion text click , add on searchbox the suggestion text ( example ( Showing results for youtube ) ) |
JS | SITUATION : I used to check my recaptcha with a simple form submit with POST to `` /login '' .I need to change my implementation for security reasons and would like to do something like:1 ) Jquery form submit.2 ) Make call to server to call verify recaptcha on the server.3 ) Receive response without reloading page.4 ) ... | < div class = '' containerMargins '' > < h1 class = `` authTitle '' > Login < /h1 > < form id= '' loginForm '' > < div class= '' form-group '' > < label > Email < /label > < input type= '' email '' class= '' form-control '' name= '' email '' id= '' loginEmail '' placeholder= '' You ca n't forget it : ) '' required > < ... | How to verify recaptcha in server call ? |
JS | What is the best way to export a module that includes submodules using an index.js . For a long time now I follow a pattern on naming and saving my web components on my projects ( Vue or React ) . But I want a more practical way to export a module using a single index to avoid cases like the following : My Pattern | import PostDetail from 'src/views/posts/PostDetail ' | What is the best way to export modules with submodules in ( Vue , React ) |
JS | I 'm using the infinitescroll.js script and it works really well . I 've found out how to replace the default functionality with a load more button , using this code : However , what I 'd like to do is allow infinite scroll to run 3/4 times and then show the .js-next-reports button . I 'm not sure how to keep track of ... | $ ( window ) .unbind ( '.infscr ' ) ; $ ( '.js-next-reports ' ) .click ( function ( ) { $ grid.infinitescroll ( 'retrieve ' ) ; return false ; } ) ; $ ( document ) .ajaxError ( function ( e , xhr , opt ) { if ( xhr.status == 404 ) $ ( '.js-next-reports ' ) .remove ( ) ; } ) ; $ grid.infinitescroll ( { // selector for t... | Allow infinitescroll.js to run X times , then load more posts |
JS | If I use jquery to select all my text inputs : They are wrapped in jQuery . I can do whatever I want with them.As a group they abide . But I seem to be missing something . I know I can see each one individually as if it was an array of objects.But the above output is just the html ; when I do that it 's no longer a jQu... | var inputs = $ ( ' # form input [ type= '' text '' ] ' ) ; inputs.css ( 'height ' , '1000px ' ) ; //muhahaha ! console.log ( inputs [ 0 ] ) ; // < input type= '' text '' / > inputs [ 0 ] .css ( 'font-size ' , '100px ' ) ; // Uncaught TypeError : Object # < HTMLInputElement > has no method 'css ' | Selecting the individuals from a group of jQuery elements |
JS | I 'm trying to use the javascript replace function to replace curly quote with straight quotes : This works great in a little proof of concept html file I 've whipped up , but when it 's in a visual studio project , it replaces the curly quote with a symbol that suggests 'unknown character ' : How can I resolve this is... | var EditedContent = content.replace ( / “ /g , ' '' ' ) ; | Javascript replace ( ) does n't work in VS - unknown character |
JS | So I was fooling around with the new exponentiation operator and I discovered you can not put a unary operator immediately before the base number.From the documentation on MDN : In JavaScript , it is impossible to write an ambiguous exponentiation expression , i.e . you can not put a unary operator ( +/-/~/ ! /delete/v... | let result = -2 ** 2 ; // syntax errorlet result = - ( 2 ** 2 ) ; // -4let x = 3 ; let result = -- x ** 2 ; // 4 | JavaScript exponentiation unary operator design decision |
JS | The regular host works , but when I use https I get this error : Any thoughts why ? this is seriously befuddling me . | import DS from 'ember-data ' ; export default DS.JSONAPIAdapter.extend ( { host : 'http : //api.theapothecaryshoppe.com ' , // host : 'https : //api.theapothecaryshoppe.com ' } ) ; Error : The adapter operation was abortedat EmberError.AdapterError ( /home/nick/the-apothecary-shoppe/portal-ember/tmp/broccoli_merge_tree... | Ember fastboot works with at http api host but not an https one |
JS | I 'm trying to convert this long JS regex to C # .The JS code below gives 29 items in an array starting from [ `` '' , '' 常 '' , '' '' , '' に '' , '' '' , '' 最新 '' , '' 、 '' , '' 最高 '' ... ] But the C # code below gives a non-splitted single item in string [ ] .Many questions in Stack Overflow are covering relatively s... | var keywords = / ( \ & nbsp ; | [ a-zA-Z0-9 ] +\ . [ a-z ] { 2 , } | [ 一-龠々〆ヵヶゝ ] +| [ ぁ-んゝ ] +| [ ァ-ヴー ] +| [ a-zA-Z0-9 ] +| [ a-zA-Z0-9 ] + ) /g ; var source = '常に最新、最高のモバイル。Androidを開発した同じチームから。 ' ; var result = source.split ( keywords ) ; var keywords = @ '' / ( \ & nbsp ; | [ a-zA-Z0-9 ] +\ . [ a-z ] { 2 , } | [ 一-... | C # Regex.Split is working differently than JavaScript |
JS | I 'm curious how .fadeTo ( ) fades an element ? Does it use an inline style of opacity to do this ? And if it does not use css opacity , then how would you control css opacity using jQuery or javascript ? This question is referring to all of the following : | .fadeTo ( ) .fadeIn ( ) .fadeOut ( ) | How does jQuery .fadeTo ( ) work ? |
JS | my code like this : My try : http : //jsfiddle.net/z8k6t3fb/1/I want get '3vw ' Is it possible ? | # image_1 { position : absolute ; top : 3vw ; } | javascript : get css prop value with unit |
JS | at the moment I have my jQuery plugin running it 's logic in if statments . For example I have : Is there a better way to go about this ? Also the same with event handlers , can I declare them inside the plugin ? | ( function ( $ ) { $ .fn.myplugin = function ( action ) { if ( action == `` foo '' ) { } if ( action == `` bar '' ) { } if ( action == `` grapefruits '' ) { } } } ) ( jQuery ) ; | Writing a better jQuery plugin |
JS | Isexactly like ? | if ( a ) { do { b ( ) ; } while ( a ) ; } while ( a ) { b ( ) ; } | Is if ( ) { do { } ; while ( ) ; } exactly like while { } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.