lang stringclasses 4
values | desc stringlengths 2 8.98k | code stringlengths 7 36.2k | title stringlengths 12 162 |
|---|---|---|---|
JS | I am making a selection panel and I am having a hard time figuring out an aspect to it . There are nine boxes and I want the user to be able to click the boxes and when clicked for the hover 's format to stay present and then ideally some sort of checkmark or something added into the border of the box . I am completely... | # project-scope-container { margin-top : 70px ; margin-left : 9 % ; width : 75 % ; height : 300px ; } # project-scope-title { font-size : 1.2em ; font-weight : bold ; margin-bottom : 15px ; } .project-option-boxes { display : inline-block ; border : 1px solid # 45ba95 ; padding : 20px 0px ; margin : 12px 20px 12px 0px ... | Keeping elements ' hover style active when clicked on |
JS | I have the following right now , but its not perfect : Basically , I have 75px from top before my content starts , and I have 60px from bottom of the page to my content.How do I make it so when I resize the window , it will always respect those dimensions ? I am using malihu scroll bar , and I am loading my view into #... | $ ( window ) .resize ( function ( ) { $ ( `` # app-views '' ) .height ( $ ( window ) .height ( ) - 140 ) ; } ) ; | jquery resize so content is always centered perfectly |
JS | I am trying to sum check box values when checked , And display it on another input field.The bellow given script is working fine . But it 's not working on a hidden div with display : none CSS , When shown with .show ( ) ; . | function showCheckboxes ( ) { $ ( '.checkboxes ' ) .show ( ) ; } $ ( document ) .ready ( function ( ) { function Calculate ( ) { var sum = 0 ; $ ( `` .add : checked '' ) .each ( function ( i , n ) { sum += parseInt ( $ ( n ) .val ( ) ) ; } ) $ ( `` # sum '' ) .val ( sum ) ; } $ ( `` .add '' ) .change ( Calculate ) ; Ca... | Add up Checkbox Values not working on hidden ` div ` when shown |
JS | How can I replace a ClassName in the code below , with a variable.I have : How can I replace where i have the ClassNames with a variable like this : Note that it is only a part of the code I have , I do not need to change the code , I just need to call a variable where those classnames are appearing . | ( function ( root , factory ) { factory ( ( root.ClassName= { } ) ) ; dragged = [ ] .slice.call ( _document.getElementsByClassName ( 'ClassName ' ) ) ; } ) ; ( function ( root , factory ) { var x = ClassName factory ( ( root.ClassName= { } ) ) ; dragged = [ ] .slice.call ( _document.getElementsByClassName ( 'ClassName ... | Replacing part of code with variable |
JS | I have this specific case where if the user routes to say topics/rendering , I need to show him a seperate Component and when user routes to topics/10 , I need to show him another Component.The problem I am facing right now is that even when I do topics/rendering , I see both of the components being rendered on screen.... | < div className= '' App '' > < Router > < Route exact path= '' / '' component= { Home } / > < Route path= '' /about '' component= { About } / > < Route exact path= '' /topics '' component= { Topics } / > < Route exact path = '' /topics/rendering '' component= { Description } / > < Route exact path= '' /topics/ : id '' ... | issue with how to render with react router |
JS | this is my first post so I 'll try to make sure I 'm following appropriate posting etiquette.I have no experience whatsoever with html , d3 , or javascript . I do however have some exposure to xml and svg . I 'm trying to work through this tutorial : [ http : //bost.ocks.org/mike/circles/ ] . I spent several hours yest... | < svg width= '' 720 '' height= '' 120 '' > < circle cx= '' 40 '' cy= '' 60 '' r= '' 10 '' > < /circle > < circle cx= '' 80 '' cy= '' 60 '' r= '' 10 '' > < /circle > < circle cx= '' 120 '' cy= '' 60 '' r= '' 10 '' > < /circle > < /svg > var circle = d3.selectAll ( `` circle '' ) ; circle.style ( `` fill '' , `` steelblu... | Modifying an SVG in HTML using d3 |
JS | I have a javascript ( node.js v12 ) async function that is used to get a resource . It first makes a call to a cache to check if the resource is cached . If it is , then the cached resource is returned . If it is not , then it gets the resource from the path , puts it in the cache , and then returns the resource . The ... | async function getResource ( path ) { const cachedResource = await getResourceFromCache ( path ) .catch ( logError ) ; if ( cachedResource ) { return cachedResource ; } else { const resource = await getResourceFromPath ( path ) ; putResourceInCache ( path , resource ) .catch ( logError ) ; // This is an async function ... | Are there any issues with returning from a function before a promise has been resolved ? |
JS | I 'm having some trouble deciphering prototypical inheritance in JavaScript , and thought of posting it here . Consider this simple example : What I ca n't understand is the utility of the line Employee.call ( this ) . Since we 're going to be setting Employee.protoype as Manager 's prototype , what 's the need for ( a... | function Employee ( ) { this.name = `` Rob '' ; this.dept = `` R & D '' ; } function Manager ( ) { //Employee.call ( this ) ; this.reports = [ `` Report 1 '' , `` Report 2 '' , `` Report 3 '' ] ; } Manager.prototype = Object.create ( Employee.prototype ) ; Employee.prototype.type = `` human '' ; m = new Manager ( ) ; c... | What 's the need for call ( ) in prototypical inheritance |
JS | This is how I replace characters before and after a word : What if I want to turn this : Into this ? | el = el.replace ( / '' \b/g , ' & ldquo ; ' ) el = el.replace ( /\b '' /g , ' & rdquo ; ' ) `` ` This is a quote `` ` < quote > This is a quote < /quote > | How to replace characters that are before and after a block/paragraph ? |
JS | I am doing a small exercise using HTML and Javascript . Basically , I have 2 input fields that I need to validate using 1 function in Javascript . The first input asks for the name and if the name is less than 3 characters , there would be an error printed , else , the error is removed . The second one asks for the loc... | < ! DOCTYPE html > < html > < head > < title > Revision < /title > < /head > < body > < nav id= '' menu '' > < /nav > < a > Full Name : < /a > < input type= '' text '' name= '' fName '' id= '' fName '' > < br/ > < div id= '' divName '' > < /div > < br/ > < a > Locality : < /a > < input type= '' text '' name= '' localit... | Getting redirected to another webpage on page load with the contents of my JavaScript array as the URL |
JS | I 'm working on a MVC project in which I display a ViewModel in several partial views within a table . I have a control in which the user can change how the table is displayed , like this : orAny time a user wants to change how the view is displayed , he has to click the submit button of the from , and the application ... | < table > < tr > < td > partial view 1 partial view 2 < /td > < /tr > < tr > < td > partial view 3 partial view 4 < /td > < /tr > < /table > < table > < tr > < td > partial view 1 < /td > < /tr > < tr > < td > partial view 2 < /td > < /tr > < tr > < td > partial view 3 < /td > < /tr > < tr > < td > partial view 4 < /td... | Best way to sort page disposition on client side |
JS | I have already created a drop-down contact menu with 2 links within them . But it seems that when I click on the contact button and then on the desired link , it just closes the dropdown menu without redirecting the user anywhere . I read somewhere that it 's because another mouse down event would trigger the : focus t... | < div class= '' contact '' > < button class= '' contactbtn '' > Contact < /button > < ul > < li > < p > For Any Enquiries→ < /p > < /li > < li > < a id= '' mail '' href= '' mailto : hello @ shekleung.com '' > hello @ shekleung.com < /a > < /li > < li > +44 7463 070158 < /li > < br > < li > < a id= '' ig '' href= '' htt... | How to make pure css dropdown menu work with two re-directable links withim them ? |
JS | I am trying to catch all these numbers with a regex but I ca n't find a pattern.Criteria for numbers : Numbers can start with `` 00 '' Numbers can start with `` + '' Numbers can contain spaces between them.it may be that before or after the phone number you have text.Regex : Sample phone Numbers : Thanks . | \b [ \+ ] ? [ ( ] ? [ 0-9 ] { 2,6 } [ ) ] ? [ -\s\. ] ? [ -\s\/\.0-9 ] { 3,15 } \b 00491234567890+4912345678900123-45678900123 4567 7890123 456 78900123 45 67 789+490123 4567 789+490123 456 7890+49 123 45 67 789123 4567 789123 456 7890123 45 67 789+49 1234567890+4912345678900049 12345678900049 1234 567 890 ( 0049 ) 123... | Phone numbers with regex ( plus and spaces ) |
JS | I have a problem with the following regular expression : Above , I expect arr [ 2 ] ( i.e . capture group 2 ) to be `` file '' , matching against the last4 character in the first line after applying a greedy . * , backtracking due to / in thepattern , and then anchoring against the end of line by $ .In fact , arr [ ] i... | var s = `` http : //www.google.com/dir/file\r\nhello '' var re = new RegExp ( `` http : // ( [ ^/ ] + ) . */ ( [ ^/\r\n ] + ) $ '' ) ; var arr = re.exec ( s ) ; alert ( arr [ 2 ] ) ; var s = `` http : //www.google.com/dir/file\r\nhello '' var re = new RegExp ( `` http : // ( [ ^/ ] + ) . */ ( [ ^/\r\n ] + ) [ \r\n ] * ... | $ in regular expression not maching against end of line |
JS | I do n't understand why the following evaluates to 3 instead of just declaring a syntax error when ran from a JavaScript REPL or through Chrome 's Developer Tools : As far as I can see , that should be a syntax error as demonstrated with : I feel like there 's just some quirky behaviour I 'm not aware of ? | { 1 , 2 , 3 } ; 3 var foo = { 1 , 2 , 3 } ; Uncaught SyntaxError : Unexpected token , | Using object notation as if it were an array - why does this evaluate ? |
JS | I want to fetch auto suggestions from Youtube using the following call : This call obtains the following JSON as a result : I am struggling however to convert this result to an array of the `` actual suggestions '' . For example , I want to store the JSON obtained above in the following format : What would be a viable ... | await fetch ( 'https : //suggestqueries.google.com/complete/search ? client=youtube & ds=yt & q=skrillex & callback=suggestCallback ' ) .then ( response = > console.log ( response ) ) `` suggestCallback & & suggestCallback ( [ `` skrillex '' , [ [ `` skrillex '' ,0 ] , [ `` skrillex bangarang '' ,0 ] , [ `` skrillex ma... | Export results from JSON in an array |
JS | I need to create a regex which should look for the last '* ' irrespective of the whitespace in the string.Then , I need to replace that string with some text.Currently , it is replacing the first occurence of '* ' in the string.How do I fix it ? Here 's my code : Here , the output should be 'Field Name* mandatory ' . B... | const regex = /\*/m ; const str = 'Field Name* * ' ; const replaceStr = ' mandatory ' ; const result = str.replace ( regex , replaceStr ) ; console.log ( 'Substitution result : ' , result ) ; | Create a regex to replace the last occurrence of a character in a string |
JS | I am trying to use jQuery to find text areas that do not have a sibling of a certain class . Currently I am using the following : Is there an alternative ? Sorry for the lack of context . The problem I am having is that I have a jquery plugin ( maxlength ) that runs multiple times ( due to dynamic changes ) and adds a ... | $ ( `` textarea '' ) .not ( $ ( `` textarea '' ) .siblings ( `` .siblingClass '' ) .siblings ( `` textarea '' ) ) | Get elements that do not have a certain sibling ? |
JS | I recently came across this pattern in the source for https : //github.com/yeoman/generator-webapp : What 's the purpose of giving the function the name `` packageJSON '' when you 're going to assign it to a variable or object property anyways ? I 've always used anonymous functions in similar cases . | AppGenerator.prototype.packageJSON = function packageJSON ( ) { this.template ( '_package.json ' , 'package.json ' ) ; } ; | What is the purpose using a named function when assigning to a variable in JavaScript ? |
JS | Hi I am new to javascript , I want to change a the format of my array to a new format as part of my project.Here 's my codeI need to change this as followingI tried each method and to loop through array to create new array but I could n't accomplish the desired format.This is what i didI am looking for any help.Thanks ... | var array= [ { Indicator : `` Population National ( % of population ) '' , Country : `` India '' , Year : `` 2012 '' , Value : `` 98.8 '' } , { Indicator : `` Population National ( % of population ) '' , Country : `` India '' , Year : `` 2013 '' , Value : `` 99.1 '' } , { Indicator : `` Population National ( % of popul... | How to group and transform an array based on multiple keys in javascript ? |
JS | This question is related to mine and explains what .data method is in Jquery.Apart from the relation to HTML5 data-* element attributes ( like < p class='foo_cl ' data-bar='gee ' > , for example ) why would I code : instead of ( I am mostly interested in the case where the Jquery selector gives one object , like for $ ... | $ ( 'body ' ) .data ( `` my_lab '' , { some : '' object '' } ) ; // §1 $ ( 'body ' ) .my_lab = { some : '' object '' } ; // §2 $ ( 'body ' ) [ 0 ] .my_lab = { some : '' object '' } ; // §3 is ugly | purpose of data in jquery ? ( vs adding my own fields to Jquery objects ) |
JS | I have a generic Factory function that should return a specific type : I would expect Typescript to throw an error because foo is not a property on the interface Widget . However , it does not.But if I modify the widgetFactory function to the below code -- the only difference being that I explicitly declare the return ... | type Factory < T > = ( ) = > T ; interface Widget { creationTime : number ; } const build : Factory < Widget > = ( ) = > { return { creationTime : Date.now ( ) , foo : 'bar ' , } ; } ; const build : Factory < Widget > = ( ) : Widget = > { return { creationTime : Date.now ( ) , foo : 'bar ' , } ; } ; | Why is n't Typescript requiring my function to return a certain type ? |
JS | I 'm trying to use the apply method to invoke the objectify function , passing an array of values and using obj as the object . However , this is not being set to the object , but rather the global environment ( window ) .The purpose of this is to get an array of strings , then pass those strings to the function object... | let obj = { } ; let arr = [ `` user.name.firstname=John '' , `` user.name.lastname=Smith '' ] ; const objectify = x = > { let cur = this , v ; return x.split ( ' . ' ) .forEach ( e = > /=/g.test ( e ) ? ( v = e.split ( '= ' ) , cur [ v [ 0 ] ] = v [ 1 ] ) : cur [ e ] ? cur = cur [ e ] : ( cur [ e ] = { } , cur = cur [ ... | JavaScript - using apply to invoke function , but 'this ' is not being set to the object passed as first argument |
JS | Can someone help me to come with with a script that automatically moves in between page when the page is idle for 3 seconds ? Currently with what i have it can only move from one page to the other but i 'm having 4 pages which i would want it to affect it all.HTMLhttp : //jsfiddle.net/91wu20fr/JQUERY | < ! DOCTYPE html PUBLIC `` -//W3C//DTD XHTML 1.0 Transitional//EN '' `` http : //www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd '' > < head > < link rel= '' stylesheet '' href= '' http : //code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css '' / > < script src= '' http : //code.jquery.com/jquery-1.11.1.min.js ''... | Move to next and subsquent pages when page is idle for 3 seconds on each page |
JS | I have read many , many ways of making makeshift classes in javascript . I 'm trying to create a giant list of items , each with a variety of variables . I need to be able to call a certain object 's properties from this list.The following code compiles , but when line 9 tries to access items.yspeed1.name , it creates ... | var itemslist = function ( ) { this.yspeed1 = function ( ) { this.name = 'Yellow Upgrade ' ; this.price = 50 ; } this.yspeed2 = function ( ) { this.name = 'Blue Upgrade ' ; this.price = 25 ; } } var newitem = document.createElement ( 'button ' ) ; newitem.innerHTML = items.yspeed1.name ; shop.appendChild ( newitem ) ; | How to make a class/object that can be referenced at multiple levels |
JS | For example , an the Array datatype has a function called pop ( ) , which I suppose is added using : But as far as I know , the only way to make it non-enumerable is to do something like this : Which is not supported by all browsers.So why does doSomething show up here , while pop ( ) does n't ? Are n't they both added... | Array.prototype.pop = function ( ) { /* ... */ } ; Object.defineProperty ( Array.prototype , `` pop '' , { enumerable : false } ) ; Array.prototype.doSomething= function ( ) { } ; var arr = [ ] ; console.log ( arr ) ; // [ doSomething : function ] | Why is native datatype properties not shown on their corresponding prototypes ? |
JS | The result is : How can I get the whole data like : or Or , does it has a simpler way to describe the relationship of 'key value ' in JSON and TypeScript | class test { name : string children : Map < string , string > =new Map ( ) constructor ( ) { this.name='KIANA ' this.children.set ( 'name ' , 'OTTO ' ) } } var t = new test ( ) console.log ( t ) console.log ( JSON.stringify ( t ) ) test { children : Map { 'name ' = > 'OTTO ' } , name : 'KIANA ' } { `` children '' : { }... | How to stringify an object of the type Map |
JS | I am sure this question has been answered numerous times in one form or another , however I am not sure what to search for to find the solution . Say we have a simple ng-repeat : in the javaScript file : Basically I want to know what should get passed in the whatDoIPassInHere parameter , which in jquery would be someth... | < div ng-repeat= '' item in items '' > < input type= '' text '' value= '' { { item.name } } '' > < a ng-click= '' getTxtBoxVal ( whatDoIPassInHere ) '' > Get Text Box Value < /a > < /div > function $ scope.getTxtBoxVal ( val ) { alert ( val ) } | AngularJS Targeting elements in current iteration in ng-repeat |
JS | I am pretty new to javascript , and I was trying to build this function I found in a challenge . I have managed to solve this , but I feel like this is a very complicated way of doing things , what would be the fastest method here ? Basically answer ( array ) should transform this : into this : Here is my code so far :... | const array = [ 1,2,4,591,392,391,2,5,10,2,1,1,1,20,20 ] ; newArray = [ [ 1,1,1,1 ] , [ 2,2,2 ] , 4,5,10 , [ 20,20 ] , 391 , 392,591 ] ; const array = [ 1 , 2 , 4 , 591 , 392 , 391 , 2 , 5 , 10 , 2 , 1 , 1 , 1 , 20 , 20 ] ; const duplicates = arr = > arr.reduce ( ( a , b ) = > ( { ... a , [ b ] : ( a [ b ] || 0 ) + 1 }... | Sorting an array , having all non-unique values nested |
JS | I 'm making an ingredients application where users insert ingredientsMy application looks like this : As you can see , the first ingredients span does n't have a X at the end , because you must have at least one ingredient , but the rest of the ingredient spans do . I 'm also using the Jquery Sortable Plugin so if you ... | $ ( 'ingredientsCOUNT > span : first ' ) .hide ( deleteButton ) ; < div class='formelementcontainer funky ' > < label for= '' ingredient '' > Ingredients < /label > < div id='ingredientsCOUNT ' class='sortable ' > < span > < input type= '' text '' class='small ' name= '' ingredient '' id= '' ingredient '' placeholder='... | Make First Ingredient never able to be deleted |
JS | Here is my jsfiddle - http : //jsfiddle.net/ganganp/x62wR/5/hover for the inner circle images not working.Where have I gone wrong ? | $ ( ' # rotator0 div ' ) .hover ( function ( ) { ssrc = $ ( this ) .find ( 'img ' ) .attr ( `` src '' ) ; valt = $ ( this ) .find ( 'img ' ) .attr ( `` alt '' ) ; ( this ) .children ( 'img ' ) .attr ( 'src ' , 'http : //placehold.it/150x150 & text='+valt ) ; } , function ( ) { $ ( this ) .children ( 'img ' ) .attr ( 's... | hover function not working as needed |
JS | I 'm trying to animate an elements height using css . The way I 'm doing it is , I added a touch event to an element . The function adds a className to the element that 's supposed to hide , i.e . get a height of 0.The problem is , when the element gets clicked , the div that 's supposed get a height of 0 pauses a seco... | transition : max-height 2s ease-in-out ; var heading = document.getElementById ( 'heading ' ) , body = document.getElementById ( 'body ' ) ; heading.addEventListener ( 'click ' , hide ) ; body.addEventListener ( 'transitionend ' , hideCallback ) ; function hide ( ) { body.className = 'hide ' ; } function hideCallback (... | Animation waits before performing |
JS | Can anyone please help me with the following , I am new to Async\Await in Javascript : I have a trivial class : I call it like this : I expected a delay of 2 seconds before seeing the result of 6.Instead I immediately see : [ object Promise ] How can I correctly await the result ? Thanks for any help . | function Thing ( ) { } Thing.prototype.ShowResult = function ( ) { var result = this.GetAsync ( ) ; alert ( result ) ; } Thing.prototype.GetAsync = async function ( ) { var result = await this.AsyncFunc ( ) ; return result ; } Thing.prototype.AsyncFunc = async function ( ) { return new Promise ( resolve = > { setTimeou... | How to call an asynchronous JavaScript function ? |
JS | As you can see here we set `` fibonacci '' as an `` iterable '' object and we loop on it with a for .. of : As expected in for of loop , console log write 1,2,3,5,8 , .. BUTif I write pre = cur ; cur = pre + cur ; instead of [ pre , cur ] = [ cur , pre + cur ] ; console.log will write 2,4,8,16 , ..Why ? Is n't destruct... | let fibonacci = { [ Symbol.iterator ] ( ) { let pre = 0 , cur = 1 ; return { next ( ) { [ pre , cur ] = [ cur , pre + cur ] ; return { done : false , value : cur } } } } } for ( var n of fibonacci ) { // truncate the sequence at 1000 if ( n > 1000 ) break ; console.log ( n ) ; } | Why destructuring works differently than in classic assignation in Javascript ( ES6 ) ? |
JS | While still struggling to read `` You do n't know JS '' , I am start to have good idea ( love this series ) . I think I get the hang of prototype but I ran into below code.And while I fully comprehend the output and its meaning , I was trying to use my understanding ( or lack thereof ) of prototype and wanted to do bel... | var myObject = { a:2 } ; Object.getOwnPropertyDescriptor ( myObject , `` a '' ) ; myObject.getOwnPropertyDescriptor | Clarification needed for prototype/object statement and chain traversal |
JS | Version3.4.0Information about environmentGoogle Chrome | 77.0.3865.120 ( Official Build ) ( 64-bit ) ( cohort : Stable ) Revision | 416d6d8013e9adb6dd33b0c12e7614ff403d1a94-refs/branch-heads/3865 @ { # 884 } OS | Windows 10 OS Version 1803 ( Build 17134.1099 ) JavaScript | V8 7.7.299.13Test Casehttps : //jsfiddle.net/a... | ( function ( ) { var canvas = new fabric.Canvas ( 'canvasWorkspaceFamiliogram ' , { selection : false } ) ; fabric.Object.prototype.originX = fabric.Object.prototype.originY = 'center ' ; var itemM = new fabric.Rect ( { width : 30 , height : 30 , fill : 'white ' , stroke : 'black ' , strokeWidth : 1 , left:50 , top:50 ... | Update Selection Box in fabric.Path |
JS | I 'm making a Genetic Algorithm for a school project . Currently I 'm building the foundation for the `` dot '' objects that move around and pick up food . I wrote some code that I thought should be able to do that and after some trial and error I came up with this . ( It 's probably not the cleanest code and I would l... | checkForTarget ( ) { let inRange = new Array ( ) ; let indexArray = new Array ( ) ; for ( let i = 0 ; i < food.length ; i++ ) { let d = dist ( food [ i ] .pos.x , food [ i ] .pos.y , this.pos.x , this.pos.y ) ; if ( d < this.sense ) { inRange.push ( food [ i ] ) ; indexArray.push ( i ) ; } } if ( ! inRange.length == 0 ... | Picking up food object in radius |
JS | TLDR : Why are function parameters not treated as var declarations ? Using var , redeclaring a variable declared using var has no effect . The original declaration remains in effect.However , using var in this way will mask a parameter of the same name . Why is the language designed like this ? In the following , varia... | function foo ( bar = 0 , bam = ( ) = > bar ) { var bar = 1 return bam ( ) } console.log ( foo ( ) ) // 0 function body > > parameter list > > outer function body > > outer parameter list > > ... global scope | Why does redeclaring an identifier in a function , mask a parameter of the same name ? |
JS | Is there a way to write custom valueOf ( ) methods for primitives ? I.e . is there a way to make 'str'+123 call alert ( ) ? | Number.prototype.valueOf=function ( ) { alert ( 'works ! ' ) ; } 'str'+123 ; // no alert'str'+ ( new Number ( 123 ) ) ; // alert | Is it possible to write a custom valueOf method for primitives in Javascript ? |
JS | I 'm a beginner in coding , and I need some help with the following code . So I have a page like the following one in the example . So far , I tried the following method . ( Please check my code and live example ) With my current method to select the checkboxes , I have to write code for each and every option like this... | $ ( `` # check_us , # check_us-1 , # check_us-2 '' ) .prop ( `` checked '' , ! 0 ) $ ( `` button.select-all '' ) .on ( `` click '' , selectAll ) ; function selectAll ( ) { $ ( `` .schoolareas '' ) .toArray ( ) .forEach ( function ( a , c , b ) { $ ( `` # check_ '' + a.id ) .prop ( `` checked '' , ! 0 ) } ) } $ ( `` but... | Check Common Dropdown Items ( JavaScript , jQuery ) |
JS | I have an object with multiple properties , each property has a value that is a string . When I try to concatenate the values of each property , it returns NaN.What am I doing wrong here , or what is the proper way of doing this ? | var urlProps = { searchTerm : `` searchSTUFF '' , baseURL : `` https : //en.wikipedia.org/w/api.php ? action=query & prop=extracts & format=json & exsentences=1 & exlimit=10 & exintro= & explaintext= & titles= % 20 & generator=search & gsrsearch= '' , tailURL : `` & rawcontinue= & callback= ? `` , finalURL : this.baseU... | Concatenating the values of an object 's properties returns NaN ( Javascript ) |
JS | I have the following javascript code : Is it possible to insert a wp custom php codeInstead of this static attributeMany thanks in advance . | $ ( window ) .scroll ( function ( ) { if ( $ ( this ) .scrollTop ( ) > 50 ) /*height in pixels when the navbar becomes non opaque*/ { $ ( '.navbar-default ' ) .addClass ( 'sticky ' ) ; $ ( '.navbar-brand img ' ) .attr ( 'src ' , 'assets/images/logo.png ' ) ; //change src } else { $ ( '.navbar-default ' ) .removeClass (... | How can I add Wordpress php code into JavaScript |
JS | I have the DOM like thisI have a click event attached to li and when I click button of block2 , that event occurred . How to prevent that to happened ? I tried using on ( ) but it does n't work . | < div class= '' modal '' > < li > < div id= '' block1 '' > < /div > < div id= '' block2 '' > < div class= '' btn-wrap '' > < button > cancel < /button > < button > save < /button > < /div > < /div > < /li > $ ( '.btn-wrap ' ) .on ( 'click ' , 'button : first-child ' , function ( e ) { e.preventDefault ( ) ; alert ( 'te... | prevent event bubling does n't work in jquery |
JS | I have one service that is globally storing all my data used through out my app.GlobalDataService ( GDS ) And a simple crud service that handles the Status of my data.StatusDataService ( SDS ) The GDS has to request all Status 's when the app first loads , then the Status Service handles any other data requests.Now I u... | angular .module ( 'app.core ' ) .service ( 'GlobalDataService ' , GlobalDataService ) ; GlobalDataService. $ inject = [ ' $ http ' , 'LineStatusService ' ] ; function GlobalDataService ( $ http , LineStatusService ) { var gds = this ; gds.data = { //all my data } gds.data.lines = LineStatusService.getLineStatus ( ) .th... | Reuse Services without circular dependencies |
JS | I have following code : I want to know when the root level of ' f ' is called , so I introduce a flag as an argument : My question is : Is there a way to know when ' f ' is called on the top level `` f ( root , ... ) '' without adding additional arguments ? | function f ( ) { // ... do stuff with arguments //and return something ... } f ( root , f ( child1 ) , f ( child2 , f ( subchild1 ) , ... . ) , ) ; f ( root , '-r ' , f ( child1 ) , f ( child2 ) , // ... ) | Function call order with the same function as arguments . Javascript |
JS | I started to learn js and now i 'm make a list of exercise . In this list i need to make a button that every time i click , a new red square appear on the screen , and always i pass the mouse over of any square the color must to changes for an aleatory one . but i only can change the color of the first square.Why this ... | let btn = document.querySelector ( `` # btn '' ) ; btn.onclick = function createSquare ( ) { let divSquare = document.createElement ( `` div '' ) ; divSquare.setAttribute ( `` class '' , `` square '' ) ; divSquare.setAttribute ( `` onmouseover '' , `` mouseOver ( ) '' ) ; let container = document.querySelector ( `` # c... | change the color of a square with onmouseover |
JS | I want to have a horizontal layout in my page ... whenever user scrolls the page instead of top-to-bottomlayout I want to have left-to-right layout ... with my code on big screens there is empty space after last section and on small screenslast section wo n't appear . | calcBodyHeight ( ) ; function calcBodyHeight ( ) { const sections = document.querySelectorAll ( '.section ' ) ; let height = null ; sections.forEach ( section = > { height += section.offsetWidth ; } ) document.body.style.height = ` $ { height } px ` ; } const container = document.querySelector ( '.container ' ) ; windo... | horizontal layout when scroll |
JS | I 'm quering my database as below : How can I display P in the place of 1 and A in the place of 0 in my report ? | < ? phpwhile ( $ date < = $ end ) { $ ttl++ ; $ student_array = array ( ) ; $ stu_name_td = `` ; mysqli_data_seek ( $ result,0 ) ; while ( $ innerrow = mysqli_fetch_array ( $ result ) ) { $ atd_query = `` SELECT * FROM attendance WHERE AttDate = ' '' .date ( ' Y-m-d ' , $ date ) . '' ' AND sl_no = ' '' . $ innerrow [ '... | How to put P in the place of 1 and A in the place of 0 |
JS | I am trying to filter the array of objects that looks like above.Let 's say I give queries for both title which is a string and customer which is an array of strings.I made a function named filterData which takes an object that looks likeI want the function to filter out the objects that have aa in the title and b in t... | const sample_table1_data = [ { title : 'aa-1 ' , customers : [ ' a ' , ' b ' ] } , { title : 'aa-2 ' , customers : [ ' a ' , ' c ' ] } , { title : 'bb-1 ' , customers : [ 'd ' , ' e ' ] } , { title : 'cc-1 ' , customers : [ ' b ' , ' e ' , ' f ' ] } , { title : 'dd-1 ' , customers : [ ' f ' , ' g ' ] } , { title : 'dd-... | Applying query filters to JavaScript array of objects |
JS | I 'm getting eslint error Unexpected string concatenation.eslint ( prefer-template ) How to fix this with template literals `` or shall I need to update eslint rule to allow this ? | const listItemClasses = classNames ( { [ ' ' + classes [ color ] ] : activeRoute ( props , prop.layout + prop.path ) , } ) ; | String Templating for object keys |
JS | I put the this keyword in a button element event handler and in another handler of the body element , but the second this keyword referred to the global window object . Why ? | < ! DOCTYPE html > < html > < head > < style type= '' text/css '' > body { height : 1000px ; } < /style > < title > Scroll < /title > < /head > < body > < button id= '' btn '' > click < /button > < script type= '' text/javascript '' > document.body.onscroll = function ( ) { alert ( this ) ; // displays [ object Window ... | Why does the 'this ' keyword inside event handlers of document.body refer to the global window object ? |
JS | I have a code snippet to include in a project , and I 'd like to know if there 's a purpose to why it was written like this or if I should clean it up . Is there an optimization trick I do n't know about ? Here 's the ( sanitized ) code snippet . Notice a , b , c , d passed in and then assigned in the function.I found ... | ( function ( a , b , c , d ) { a = '//url/to/js/file.js ' ; b = document ; c = 'script ' ; d = b.createElement ( c ) ; d.src = a ; d.type = 'text/java ' + c ; d.async = true ; a = b.getElementsByTagName ( c ) [ 0 ] ; a.parentNode.insertBefore ( d , a ) ; } ) ( ) ; | What 's the purpose of javascript parameters that are overwritten in the function ? |
JS | I was doing some stuff and I ran into a problem that I ca n't understand.I simplified the code to get that : What result do you expect ? 1 Doneis logged.When I changetoI get 5 Donewhat I expected for the first time.Can you help me to find what is wrong ? I do n't get it . | function somePromise ( ) { return new Promise ( ( resolve , reject ) = > { resolve ( 1 ) ; } ) ; } async function main ( ) { let count = 0 ; const arr = [ 1 , 2 , 3 , 4 , 5 ] ; const promises = arr.map ( async ( ) = > { count += await somePromise ( ) ; } ) await Promise.all ( promises ) ; console.log ( count ) ; } main... | Assignment operator , map and promises . What 's wrong with that code ? Javascript |
JS | My useEffect is running as it should be , but once it is complete , it does n't update the state of my Component . It always shows the previous render . I thought I have added all the appropriate dependencies , but it still gives me stale data . Here is my hook : Here is the component I am using it in : SearchResult re... | export default function useSort ( items , sortKey , sortAscending ) { let [ sorted , setSorted ] = useState ( items ) ; useEffect ( ( ) = > { let sortedItems = sortKey ? items.sort ( ( a , b ) = > { if ( ! a [ sortKey ] & & b [ sortKey ] ) return sortAscending ? -1 : 1 ; if ( a [ sortKey ] & & ! b [ sortKey ] ) return ... | Why do I continue to have stale data in my useEffect ? |
JS | I have a HTML with my Tic Tac Toe field . With several onlick 's HTML ( game.html ) : When I click on one of the onclick 's , my code runs the putScore function inside my gameController.js . Inside this js I want to check if the used user_id inside my payload is the same as the player1 ID I get from my DB.If this is th... | < table class= '' nes-table is-bordered is-centered '' id= '' tttpattern '' > < tbody > < tr > < td class= '' square '' id= '' 0.0 '' onclick= '' gameController.putScore ( ' 0.0 ' ) '' > < /td > < td class= '' square '' id= '' 0.1 '' onclick= '' gameController.putScore ( ' 0.1 ' ) '' > < /td > < td class= '' square '' ... | Writing inside a .html using JQuery and an if Statement in Javascript |
JS | I am sort of new to Javascript and wanting to clear something up , I have read something about Hoisting and feel this might be the reason and answer to my question but why does the log , log out the last assignment to my constant ? Both results display bob and not Roger then Bob . It would be great if somebody could ex... | const people = [ { name : `` Roger '' , age : 29 , role : `` Secret Agent '' } , { name : `` Jamie '' , age : 35 , role : `` Secret Agent '' } ] console.log ( `` people '' , people ) ; people [ 0 ] .name = 'bob ' ; console.log ( `` people '' , people ) ; | Why does console log , log out a variable thats already been assigned as the new assignment |
JS | I want to use “ selected ” in option attribute in name attribute using Javascript or jQuery . It means I want to use name= '' 1 '' option as selected one when the page is loaded . I tried with the below code . But it not workes.Code : Jquery : Demo : http : //jsfiddle.net/muthkum/zYRkC/Thank you . | < select id= '' countryselect '' name= '' country '' > < option value= '' 1 '' name= '' 0 '' > Afghanistan < /option > < option value= '' 2 '' name= '' 0 '' > Albania < /option > < option value= '' 3 '' name= '' 0 '' > Algeria < /option > < option value= '' 4 '' name= '' 1 '' > Malaysia < /option > < option value= '' 5... | How to use selected in option attribute in name attribute using Javascript or jQuery ? |
JS | Here 's the HTMLI am trying to add a number in the p tag that is a child of the .progressButton . I need the number to increase with every p tag . I 'm having issues with my javascript loop . I assume the issue is in the way .text ( buttonNumber [ ] ) ; is indexing . How do I solve this ? | < li class= '' carousel-btn-wrapper '' > < div class= '' progressButton '' > < p > < /p > < /div > < button class= '' videoCaroselButton '' > Welcome < /button > < /li > < li class= '' carousel-btn-wrapper '' > < div class= '' progressButton '' > < p > < /p > < /div > < button class= '' videoCaroselButton '' > Video Na... | Javascript loop indexing issue |
JS | So I have this JS code : There 's probably some answer around here , but I can not even describe the problem ; so I went with `` losing node reference '' , even though it 's not what happens here . ( edit : in fact , that 's what happens here , silly : ) ) So ... Please try the code as it is . It works , the link is re... | var pElt = document.createElement ( `` p '' ) ; var aElt = document.createElement ( `` a '' ) ; aElt.textContent = `` Text '' ; aElt.href = `` # '' ; pElt.appendChild ( aElt ) ; aElt.style.color = `` red '' ; pElt.innerHTML += `` < span > and more text < /span > '' ; //aElt.style.color = `` red '' ; document.getElement... | Losing a node reference ? ( javascript ) |
JS | I mean Object-B is included in Object-A , when all attributes of Object-B are included in the object-A and its values are the same in the object-A.My question is : Does ES6/ES7 has built-in API more elegant and brief for that ? For example , to extend object from origin , ES6 brought Object.assign ( o1 , o2 ) ? Is ther... | var obj_b= { a:1 , d:3 } var obj_a= { a:1 , b:22 , c:33 , d:3 } // -- > obj_b includes in obj_a var obj_c= { a:1 , f:4 } ; isIncluded= ( small , big ) = > Object.keys ( small ) .every ( ( k ) = > big [ k ] === small [ k ] ) console.log ( 'Does `` obj-b '' included in `` obj-a '' ? ' , isIncluded ( obj_b , obj_a ) ) con... | check if literal object included in other object with Built-in API |
JS | I am writing a code in javascript dhtmlx . I have an onclick event on a grid . When i click the grid a window shows up which i want to be gone after 4 sec.i tried the setTimeOut but after 2-3 consecutive clicks it messes up with the time and hides the windows almost immediately . Here is the code : What am i doing wron... | var dhxWindow = new dhx.Window ( { modal : false , header : false , footer : false , resizable : false , css : `` toolbar '' , movable : false , height : 130 , expire : 4000 } ) ; var toolbar = new dhx.Toolbar ( `` toolbar_container '' , { } ) ; grid.events.on ( `` CellClick '' , function ( row , column , e ) { var dat... | Javascript SetTimeOut on click does n't respect the time delay after 2-3 clicks |
JS | I 'm reading the source of mongoose , find such code in https : //github.com/LearnBoost/mongoose/blob/master/lib/collection.js # L23 : I do n't understand why this line exist . Does it here just for generating document ? | /** * The collection name * * @ api public */Collection.prototype.name ; | Why just write a field and not doing anything with it ? |
JS | I am bit confused here.I am working on a dynamic project and I want to apply different css to divs which have same class but no id . How can I apply different css say to first div with same class , and then different css to second div of same class and so on ... Let 's say I have fullwidthContainer class applied to 3 d... | function emphatic ( ) { var totalContainers=document.getElementsByClassName ( 'fullwidthContainer ' ) var className=1 ; for ( var i = 0 ; i < totalContainers.length ; i++ ) { className=className+1 ; totalContainers [ i ] .setAttribute ( `` class '' , `` dropdown_5columns fullwidthContainer customMenuClass '' ) ; } ; } ... | How can you grab elements in dom and apply different css without id ? |
JS | i need to select all parents which has same class using jQuerynow i can select only one element but i want to select all parent elementsin this i need to select the parent elements of .text-3 which has text as a classname | < div class= '' text '' > < div class= '' text '' > < div class= '' text '' > < div class= '' text '' > < div class= '' text '' > < div class= '' text-3 '' > hi < /div > < /div > < /div > < /div > < /div > < /div > | Select all parents which has same classname |
JS | I am trying to target the parent node , which is a div of a link tag ( a ) in my code , I have tried target.parentNode but that does not work , maybe as I am using querySelectorAll ? . My code so far is : Html : Any idea 's ? | function remove ( ) { var target = document.querySelectorAll ( ' a [ data-type= '' data '' ] ' ) , i ; for ( i = 0 ; i < target.length ; i++ ) { if ( target.length > 1 ) { target [ i ] .remove ( ) ; } } } remove ( ) ; < div class= '' carousel-slide '' > < a data-type= '' data '' data-type= '' image '' > < img class= ''... | How to get and remove the parentNode of querySelectorAll |
JS | Suppose we have the following HTML : Does jQuery have a built-in mechanism for retrieving all values of a specific attribute ? And if not , then what is the most efficient way to retrieve them ? Eg , something similar to : $ ( 'entry ' ) .attrs ( 'id ' ) , returning a list of values across all elements which returns so... | < entries > < entry id= '' 1 '' / > < entry id= '' 2 '' / > < entry id= '' 3 '' / > < entry id= '' 4 '' / > < /entries > | Grab values of an attribute from all elements in jQuery |
JS | I wanted to detect value changes on the display CSS property by changes on the class attribute , and I came up with the below snippet.I know getComputedStyle returns a read-only live CSSStyleDeclaration object , but as the object updates automatically when the element 's styles are changed , I 've assumed it assigns it... | let parent = document.querySelector ( `` .parent '' ) ; let child = parent.querySelector ( `` .child '' ) ; let style = getComputedStyle ( child ) ; let display = Symbol ( `` display '' ) ; style [ display ] = style.display ; Object.defineProperty ( style , `` display '' , { get ( ) { console.log ( `` getter '' ) ; ret... | Why does n't defining the accessor descriptor of a property of computedStyle work ? |
JS | I 'm trying to understand this behaviour : In contrast to : Why does the Date addition result in a string when Date.prototype.valueOf returns a number ? Here is naive translation of the Addition Operator 's spec to JavaScript However , if I invoke this with a Date object , it returns a numeric value : Can someone shed ... | var d = new Date ( ) ; console.log ( +d ) ; // 1458049171381console.log ( 1 + d ) ; // '1Tue Mar 15 2016 09:39:31 GMT-0400 ( EDT ) ' var obj = { valueOf : function ( ) { return 123 ; } } ; console.log ( +obj ) ; // 123console.log ( 1 + obj ) ; // 124 function ToPrimitive ( x ) { return x.valueOf ( ) ; } function IsStri... | Why does Date addition result in a string ? |
JS | I created a pyramid using JavaScript and below is the code that I tried so far using for loop : Pretty basic ! But I am trying to bind the result with HTML element , say with div as follows : Instead it shows five stars in a row rather than the format in JS seeing in the console . Anything that I am missing here ? Full... | function showPyramid ( ) { var rows = 5 ; var output = `` ; for ( var i = 1 ; i < = rows ; i++ ) { //Outer loop for ( var j = 1 ; j < = i ; j++ ) { //Inner loop output += '* ' ; } console.log ( output ) ; document.getElementById ( 'result ' ) .innerHTML = output ; output = `` ; } } document.getElementById ( 'result ' )... | Bind JS Pyramid in HTML |
JS | I am having trouble trying to work out why when clicking the dropdown arrow too quickly the options in the dropdown will remain even after it has closed.HTMLCSSJavaScriptThe code was a little long so here is the JSfiddle that illustrates the behaviour : https : //jsfiddle.net/andylyell/jkjxmLxx/Thank you ! | < div class= '' dropdown-container '' > < div class= '' dropdown-header '' > < h5 class= '' js-title-hook dropdown-title '' > Option 1 < /h5 > < div class= '' toggle-button '' > < p > & darr ; < /p > < /div > < /div > < div class= '' dropdown-options '' > < ul class= '' dropdown-options-list '' > < li class= '' js-hook... | Dropdown bug , if clicked too quickly , options in dropdown remain visible |
JS | I 'm a beginner to jest and I try to test a firebase insert with jest . In case I have a class component called Orders and connect the firebase action method as a prop called fetchOrders.Here is my setup , OrderAction.jsOrders.jsOrders.test.jsThen I run the test case , here is the result ( node:24100 ) UnhandledPromise... | import { app } from `` firebase '' ; import { DATABASE_COLLECTION_ORDERS , } from `` ../../config '' ; export const fetchOrders = ( ) = > async ( dispatch ) = > { const objList = [ ] ; app ( ) .firestore ( ) .collection ( DATABASE_COLLECTION_ORDERS ) .get ( ) .then ( ( snapShot ) = > { snapShot.forEach ( ( doc ) = > { ... | Test class component firebase action with Jest |
JS | Is this the correct way to bind data using Observables ? if it is , what else is wrong with my code that makes the selectedCourse variable equal undefined ? I expect both console.log statements to return the same thing , but only the first console.log returns the data , which is an object with golf course information ,... | this.golfDataService .getGolfData ( id ) .subscribe ( data = > { this.selectedCourse = data.data console.log ( data.data ) } ) setTimeout ( function ( ) { console.log ( this.selectedCourse ) } , 2000 ) ; } | need help data binding with Observables in angular |
JS | Given two classes where I want to give the methods of one to another : How come this works : But this does n't ? To be clear , I 'm not asking how to give one class 's methods to another , but why prototype behaves like this.Bonus question : what 's the difference between defining a method inside a class block and defi... | class a { } class b { say ( ) { console.log ( 'hello ' ) } } var foo = new a ( ) ; a.prototype.say = b.prototype.say ; foo.say ( ) ; //'hello ' a.prototype = b.prototype ; foo.say ( ) ; //foo.say is not a function | Why ca n't I substitute a class 's prototype with another class 's ? |
JS | I ’ m trying to replace all spaces within a string with hyphens . I tried this : But it only replaces the first instance of a space and not the ones after it . What is the regex to make it replace all empty spaces ? | h3Text.replace ( /\s/ , '- ' ) ; | How to make this regex replace work on all characters , not just the first ? |
JS | My eyes must be deceiving me , but when I call setMonth ( 1 ) should n't the date of that date object be February ? ( Today is March 30 , 2016 ) Results in : | x = new Date ( ) ; y = new Date ( ) ; x.setMonth ( 1 ) ; document.write ( x.toString ( ) + ' < br > ' + y.toString ( ) ) ; | Javascript date looks wrong when changing the month |
JS | I want to know when obj ! == obj can be true ? This is what I saw a line of code in the book , I was very puzzled . | var result = class2type [ ( obj == null || obj ! == obj ) ] ? obj : toString.call ( obj ) ] || obj.nodeName || `` # '' ; | When can obj ! == obj be true ? |
JS | Suppose I have an objectI 'm able to access property a via obj [ `` a '' ] but I 'm also able to access it via obj [ [ `` a '' ] ] . How is that possible ? | obj = { a : 1 } | Why does JS allow property access with an array as key ? |
JS | As I was playing around trying to build a simple text carousel , I came across an issue I am having a difficult time understanding.The layout is simple . I have a wrapper and the text I want the carousel to cycle through.The issue I am having , however , seems as far as I can tell to be coming from the setInterval meth... | let animateSlide = setInterval ( moveSlide , 1200 ) ; function moveSlide ( ) { let carousel = document.getElementById ( `` wordCarousel '' ) ; let firstSlide = carousel.children [ 0 ] ; let createID = document.createAttribute ( `` id '' ) ; createID.value = `` active '' ; firstSlide.setAttributeNode ( createID ) ; caro... | setInterval ( ) Method creating strange overlap |
JS | I have a simple form that I can fill up its textboxes and there is one textbox EndDate which is empty of course . After filling all the info , I can click the Save button to finalize everything.Below is my code for references : The problem is for my EndDate , if it 's left empty and I click on the save button , it stil... | function updateData ( id , uniquecode , startdate ) { var enddate = $ ( ' # txtEndDate ' ) .val ( ) ; var radioEnableStatus = $ ( `` input [ name='radioEnableStatus ' ] : checked '' ) .val ( ) ; $ .ajax ( { url : 'updateUrl.jsp ' , type : 'POST ' , data : { 'id ' : id , 'uniquecode ' : uniquecode , 'startdate ' : start... | Text validation required attribute on non-submit button ? |
JS | I have calendar like html tables.likeI would like to change its classes like calendar schedule , if I clicked cell2 , forward 3day 's classes are changed . ( I attached images ) ①Are there any good way to realize it ? ②Are there any other ways to realize schedule like expression ( result image is illustrated below ) , ... | < td id= '' 1 '' > 1 < /td > < td id= '' 2 '' > 2 < /td > < td id= '' 3 '' > 3 < /td > < td id= '' 4 '' > 4 < /td > < td id= '' 5 '' > 5 < /td > < td id= '' 6 '' > 6 < /td > < td id= '' 7 '' > 7 < /td > < td id= '' 8 '' > 8 < /td > < td id= '' 9 '' > 9 < /td > .outpatient { border-bottom : 3px solid yellow ; } $ ( func... | How to change classes like schedule in html calendar tables |
JS | Functionality : User will navigate from the `` Instruction '' Page ( 1st Page ) to the `` Game '' Page ( 2nd Page ) and play the game designed . `` Instruction '' Page has a list of instructions for users and a start button that when clicked will navigate users to the `` Game '' page . `` Game '' Page has got a fade-in... | function Page2 ( ) { var BooleanPlay = true ; $ ( `` # page1 '' ) .hide ( ) ; $ ( `` # page2 '' ) .show ( ) ; //To check if the game is being played , will call MainGame method , else wouldnt start MaiinGame and reset counter and speedto original value if ( BooleanPlay == true ) { console.log ( `` Game Reset '' ) ; rol... | Game fails to check condition and starts in the background |
JS | Is there a way to make the width of the image , when it transitions into another line to take up as much room as possible ? For example , if the images are displayed next to each other , as soon as one of them drops to the next line , that image on the next line expands to container 's width . I believe I saw this bein... | body , html { padding:0 ; margin:0 ; } * { box-sizing : border-box ; } .grid img { float : left ; height:100px ; } .grid { display : flex ; flex-grow:2 ; flex-wrap : wrap ; } < div class= '' grid '' > < img src= '' http : //www.keenthemes.com/preview/metronic/theme/assets/global/plugins/jcrop/demos/demo_files/image1.jp... | Expand Image to container width when moving to next line |
JS | I 'm trying to get my head around using javascript in the html < canvas > , and I started with the MDN Breakout game tutorial . Here is how the complete game looks like . I 'm stuck with one of the exercises and I really could not find any solution to my issue after an hour of googling ! ! : ( ( . The following code ge... | ctx.beginPath ( ) ; ctx.arc ( x , y , radius , 0 , Math.PI * 2 ) ; ctx.fillStyle = ' # FFFFF ' ; ctx.fill ( ) ; ctx.closePath ( ) ; const canvas = document.getElementById ( 'canvas ' ) ; const ctx = canvas.getContext ( '2d ' ) ; ctx.beginPath ( ) ; ctx.rect ( 0 , 0 , 20 , 40 ) ; ctx.fillStyle = 'cyan ' ; ctx.fill ( ) ;... | Canvas.getContext : changing the colour of an object once an event happens |
JS | I know I 'm going to get the people who say I simply should n't do this , but I am curious how people accomplish it . I know I 've seen where you can type the name of a property and get one value , but then you add the parenthesis to the end and it accesses a method.Visually , I 'm saying this : The question is how ? | foo returns 'bar'foo ( ) performs a function | javascript : Assign method and string to the same property name |
JS | I am new to angular jsController is not working correctly in my codei am trying to run following codebut its not giving desire output .please tell me if i am doing something wrong . | < ! DOCTYPE html > < html data-ng-app > < head > < title > Using AngularJS Directives and Data binding < /title > < /head > < body > name < br / > < div data-ng-controller= '' SimpleController '' > < input type= '' text '' data-ng-model= '' name '' / > { { name } } < ul > < li data-ng-repeat= '' cust in customers | fil... | controller function in angularjs ? |
JS | As RIAs and SPAs ( or web apps with heavy javascript usage ) have become more and more popular , I 've been running into systems that , instead of using good old a href hyperlinks , I see them utilizing constructs using onclick with JavaScript code that manipulates navigation . This is particularly true with images.For... | < a href= '' some_url '' > < img src= '' ... . '' / > < /a > < div ... onclick='SomeJsFunctionThatNavsToAnotherPage ( ) ' > < img src= '' ... '' / > < /a > | Use of JavaScript in lieu of hyperlinks |
JS | While this is rendered as expected : if I put it together : The # each types is empty . The template helpers : And some of the template code : Even when replacing { { # each restMenuSideItems } } by { { # each ../restMenuSideItems } } , nothing appears.What 's wrong ? | { { # each Items } } // a collection { { title } } { { /each } } { { # each types } } // another ollection { { refId } } { { /each } } { { # each Items } } { { title } } { { # each types } } { { refId } } { { /each } } { { /each } } Template.menuItems.helpers ( { restMenuItems : function ( ) { return RestMenuItems.find... | Why does nested each in template output nothing |
JS | I am reading `` The JavaScript Handbook '' by Flavio Scopes . He introduces the concept of Generators.Output { value : 5 , done : false } Output : { value : 14 , done : false } I understand the first output , but I do n't understand the second one . Why is the output 14 ? My understanding is that the next time .next ( ... | function* calculator ( input ) { var doubleThat = 2 * ( yield ( input / 2 ) ) var another = yield ( doubleThat ) return ( input * doubleThat * another ) } // He then runs the following codeconst calc = calculator ( 10 ) console.log ( calc.next ( ) ) calc.next ( 7 ) ; | Javascript Generators question - explain this code |
JS | I ca n't figure out how to use a Javascript constructor method in a jQuery .click method . I 'm trying to get a button 's function to change dynamically based on a constructor . Here 's the set up : needs to call a method that changes depending on another button . The following is my broken code : I ca n't figure out h... | < button onclick= '' '' > < /button > function GloveMode ( name , array ) { this.colorArray = array ; this.displaySettings = function ( ) { //Title $ ( `` # displayTitle '' ) .text ( this.name ) ; //Display Color Set $ ( `` # displayColors '' ) .empty ( ) ; //Totally Broken $ ( `` # upArrow '' ) .click ( function ( ) {... | How do you use Javascript constructor methods in a jQuery statement ? |
JS | How is the output of 1 displayed for a ? What does thewithin the function body perform ? | var a = 1 ; function b ( ) { a = 10 ; return ; function a ( ) { } } b ( ) ; alert ( a ) ; return ; function a ( ) { } | Function Scopes Understanding Unclear |
JS | In my index.html ( HTML/Javascript ) I have : On my Server I have : After logging in , I set session [ 'venue_id ' ] = True and move to index.html . The output I get is : My question : After the initial run , I keep the index.html page open and then stop and start my project through supervisor . At this point why do I ... | $ ( document ) .ready ( function ( ) { namespace = '/test ' ; var socket = io.connect ( 'http : // ' + document.domain + ' : ' + location.port + namespace ) ; socket.on ( 'connect ' , function ( ) { socket.emit ( 'join ' , { room : 'venue_1 ' } ) ; } ) ; socket.on ( 'my response ' , function ( msg ) { $ ( ' # log ' ) .... | Restarting Supervisor and effect on FlaskSocketIO |
JS | The problem is , the Z.ABC is not the variable under the function Shape and Rectangle , it should hit error because ABC is not the variable under shape and rectangle function.How to disable unknown variable , not allow to declare unknown variable outside the function ? | function Shape ( X , Y ) { this.X = X ; this.Y= Y ; } function Rectangle ( Name , Desc , X , Y ) { Shape.call ( this , X , Y ) ; this.Name = Name ; this.Desc = Desc ; } var Z = new Rectangle ( 'Rectangle ' , `` ,25,25 ) ; Z.ABC = '123 ' ; | Disable unknown variable in function |
JS | I have a Person constructor function like so with the method sayHelloThen I define a different version of the sayHello method on the prototype of Person : Now if I create a Person instance and call sayHello on it - I notice that it is using the version of sayHello which is defined on the prototype.This to me is confusi... | var Person = function ( firstName , lastName ) { this.lastName = lastName ; this.sayHello = function ( ) { return `` Hi there `` + firstName ; } } ; Object.defineProperties ( Person.prototype , { sayHello : { value : function ( ) { return 'Hi there ' ; } , enumerable : true } } ) ; var JoeBlow = new Person ( 'Joe ' , '... | Property on the prototype overrides the property of the actual object ? |
JS | I have found a piece of code in my company 's project like the following : I do n't understand what reloop does , can anyone give a simple explanation ? | while ( condition ) { code ... reloop : { if ( somethingIsTrue ) { break reloop ; } } code ... } | What does this syntax mean which likes ` functionName : { } ` ? |
JS | I currently store a few jQuery snippets inside an array which is stored inside a function . Once I call the function from my codebase , every jQuery snippet is executed . Hence , preventing me from working through the array.The following code is an example : How can I assure that when deselect ( ) is called , that only... | var remove = [ jQuery ( `` # mesh option : selected '' ) .removeAttr ( `` selected '' ) , jQuery ( `` # pipetype option : selected '' ) .removeAttr ( `` selected '' ) , jQuery ( `` # caboption option : selected '' ) .removeAttr ( `` selected '' ) , jQuery ( `` # bedsize option : selected '' ) .removeAttr ( `` selected ... | Do not execute jQuery stored inside array each time function is called |
JS | I 'm trying to figure out how to make a track for this car game I 'm working on . The current issue is that when I 'm drawing the track , the coordinates of the drawing get transformed relative to the coordinates of the car . Sorry , it 's kind of hard to explain , but if you look at the code below you 'll see what I m... | var MAX_VELOCITY = 3 ; class Car { constructor ( x , y , angle ) { this.x = x ; this.y = y ; this.angle = angle ; this.velocity = 0 ; this.accel = 0 ; this.width = 40 ; this.height = 80 ; } show ( ) { fill ( 255 , 0 , 255 ) ; stroke ( 0 ) ; translate ( this.x , this.y ) ; rotate ( this.angle ) ; rect ( 0 , 0 , this.wid... | transforming coordinates while drawing in p5.js |
JS | I recently read this article tries to explain how JavaScript 's ability to manipulate functions could be used to let every computer in the world to do a small part in processing all the information on the internet . The way I understand it is this : the function map allows you to call a function to every element in an ... | function map ( fn , a ) { for ( i = 0 ; i < a.length ; i++ ) { a [ i ] = fn ( a [ i ] ) ; } } map ( function ( x ) { return x*2 ; } , a ) ; | How does Javascript 's ability to use undeclared functions as objects help in dividing a task between computers ? |
JS | I have a string that looks like thisIt 's really a grid that looks like this without the newlines ( just has < br > , no actual newlines ( \n ) ) I want to bold a certain section of this grid that can change every time , for this example lets say I want to bold 8617 . ( This number could be longer and stretch multiple ... | 16427171479924442928230863465674813919123162824586 < br > 17866458359124566529476545682848912883142607690042 < br > 2421902671055626321111109370544217506941658960408 < br > 07198403850962455444362981230987879927244284909188 < br > 16427171479924442928230863465674813919123162824586 < br > 1786645835912456652947654568284... | Highlighting a specific area of a grid containing < br > and reformatting the grid |
JS | I have this string ( notice the multi-line syntax ) : And I want a regex that returns ( with match ) : So I tried str.match ( /Number ( ? : One|Two ) : ( . * ) /g ) ; , but that 's returning : There can be any whitespace/line-breaks before any `` Number '' word.Why does n't it return only what is inside of the capturin... | var str = ` Number One : Get this Number Two : And this ` ; [ str , 'Get this ' , 'And this ' ] [ `` Number One : Get this '' , `` Number Two : And this '' ] | Why is this regex matching also words within a non-capturing group ? |
JS | I 'm developing a website using the node.js/express stack and I 'm trying to develop in the functional style which is pretty new to me . The express method res.send requires the function to be called as a method because it refers to this in the body , but calling methods does n't work naturally in the functional style.... | ( function ( ) { `` use strict '' ; function Foo ( ) { function bar ( ) { console.log ( this.x ) ; } return { bar , get baz ( ) { var s = this ; return ( ) = > s.bar ( ) ; } } } var a = new Foo ( ) ; a.x = 5 ; a.bar ( ) ; a.baz ( ) ; var b = a.bar ; var c = a.baz ; //b ( ) ; // throws an error because ` this ` is not d... | Encapsulating methods behind Getters |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.