lang stringclasses 4
values | desc stringlengths 2 8.98k | code stringlengths 7 36.2k | title stringlengths 12 162 |
|---|---|---|---|
JS | I 'm working with some mark-up where we have a number of html blocks/controls sitting within an outer container , this container is basically a foundation row with a max-width.In certain situations I need blocks to break out of this container , to extend beyond the max-width and occupy the full width , but remain in it... | < div class= '' row '' > < div > < em > Regular block here < /em > < /div > < div class= '' full-width '' > < em > Full width block here < /em > < /div > < div > < em > Regular block here < /em > < /div > < /div > < div class= '' row '' > < div > < em > Regular block here < /em > < /div > < /div > < div class= '' full-... | Making an element extend outside its parent with jQuery |
JS | I am fairly new and do n't really know how to word this question , so please bear with me . I would like to keep sets of data using arrays in javascript and access them sequentially using a counter . For example , I would like to display every piece of data about a person , one person at a time . Right now I am using s... | var firstNames = new Array ( `` John '' , `` Bob '' , `` Anna '' , `` Natalie '' ) ; var lastNames = new Array ( `` Smith '' , `` Price '' , `` Johnson '' , `` Baker '' ) ; var ages = newArray ( 34 , 51 , 12 , 83 ) ; counter++ ; firstNames [ counter ] ; lastNames [ counter ] ; ages [ counter ] ; var person1 = new Array... | Beginner Javascript Arrays and Counter |
JS | I am building a system where users associate tags with posts , not unlike SO . I am having a spot of bother implementing tag synonyms.Here I have a table called Tags : And I have another called TagSynonyms : The server is implemented using Node and the user enters some tags as a comma-delimited string : In this case , ... | | TagName || -- -- -- -- -- -- || Python || JavaScript || Node | | SynonymId | SourceTagName | TargetTagName || -- -- -- -- -- -| -- -- -- -- -- -- -- -| -- -- -- -- -- -- -- -|| 1 | Py | Python || 2 | Python2 | Python | var input = 'Py , Flask'var tags = request.tags.split ( ' , ' ) ; tags.forEach ( function ( tag ) {... | How do I map tags to tag synonyms ? |
JS | I am trying to keep my buttons concise inside a menu nav bar but I noticed most of the contents in the nav bar act as links , I want to store table in my buttons , inside the nav bar . I do n't know if this is possible or sensible . I am really new at this ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...... | < ! DOCTYPE html > < html > < head > < style > body { font-family : 'Lato ' , sans-serif ; } .overlay { height : 100 % ; width : 0 ; position : fixed ; z-index : 1 ; top : 0 ; left : 0 ; background-color : rgb ( 0,0,0 ) ; background-color : rgba ( 0,0,0 , 0.9 ) ; overflow-x : hidden ; transition : 0.5s ; } .overlay-con... | Is it possible for contents in a nav bar to act as buttons not links |
JS | I 'm trying to understand why we have to bind an object null to the functionWhy ca n't we just do this.add ( `` New Note '' ) ? | add ( text ) { this.setState ( prevState= > ( { notes : [ ... prevState.notes , { id : this.nextId ( ) , note : text } ] } ) ) } render ( ) { return ( < div className= '' board '' > { this.state.notes.map ( this.eachNote ) } < button onClick= { this.add.bind ( null , `` New Note '' ) } id= '' add '' > Add note < /butto... | Reactjs function binding on event handler |
JS | Here is a beautifully animated border in pure CSS . What if we want this animated borders as a frame and add an image as the content inside it.When I add the image it just overlays the frame , But I want to put the image inside the frame , not over it.I have tried my best but I ca n't find a solution without a hand.Her... | //addimage ( ) ; // uncomment this to add the image to the framefunction addimage ( ) { let pictureSource = 'https : //www.architectureartdesigns.com/wp-content/uploads/2013/03/ArchitectureArtdesigns-8.jpg ' ; let image = document.createElement ( 'img ' ) ; image.setAttribute ( `` id '' , `` shot '' ) ; var node = docu... | Add an image dynamically to this beautiful frame |
JS | Let say I have these two examples ( A = 1 ) and ( B = 2 ) ( A = 1 ) ( B = 2 ( ) ) . I need a way to get the following array : [ ( ] , [ A ] [ = ] [ 1 ] , [ ) ] , [ and ] , [ ( ] , [ B ] , [ = ] , [ 2 ] , [ ) ] [ ( ] , [ A ] [ = ] [ 1 ] , [ ) ] , [ ( ] , [ B ] , [ = ] , [ 2 ] , [ ( ] , , [ ) ] [ ) ] What I tried to do i... | function findExpressionDelimeter ( textAreaValue ) { var delimiterPositions = [ ] ; var bracesDepth = 0 ; var squareBracketsDepth = 0 ; var bracketsDepth = 0 ; for ( var i = 0 ; i < textAreaValue.length ; i++ ) { switch ( textAreaValue [ i ] ) { case ' ( ' : bracketsDepth++ ; delimiterPositions.push ( i ) ; break ; cas... | Getting out an expression |
JS | I am trying to create an interactive map using leaflet and topojson layer . I want to do the following:1- When one clicks a certain topojson polygon , it should remove.2- When one clicks the other polygon , it should remove and the previously clicked polygon should be added back.So basically there can only be one polyg... | function addRegions ( map ) { var regionLayer = new L.TopoJSON ( ) ; $ .getJSON ( 'map-developmentregions.topo.json ' ) .done ( addRegionData ) ; function addRegionData ( topoData ) { regionLayer.addData ( topoData ) ; regionLayer.addTo ( map ) ; regionLayer.eachLayer ( handleLayer ) ; } function handleLayer ( layer ) ... | Retrieving removed TOPOJSON polygon on clicking a new one |
JS | These days most of my work is related to js developing.However I suddenly found that I am confused with some questions.Check this code ( I add one method to a custom class ) : Now , use it.Now , I wonder how many copies of the function `` innerFun01 '' and `` innerFun02 '' will be created in the memory ? I am really co... | MyCustomClass.prototype.fun=function ( xx ) { this.options= { ... .. } function innerFun01 ( ) { } function innerFun02 ( ) { } } var mcc=new MyCustomClass ( ) ; mcc.fun ( xxxx ) ; var mcc2=new MyCustomClass ( ) ; mcc2.fun ( xxxx ) ; | how many copies of the inner function will be created |
JS | I am trying to mock the times function from the JavaScript library Underscore.js.This function accepts two syntaxes : andSo far I succeeded to mock the first one by creating an _ object like this : And the second syntax by creating an _ function which returns an object : But I ca n't use these 2 methods together . I ne... | _.times ( 3 , function ( n ) { console.log ( `` hello `` + n ) ; } ) ; _ ( 3 ) .times ( function ( n ) { console.log ( `` hello `` + n ) ; } ) ; var _ = { times : function ( reps , iteratee ) { // a loop } } ; function _ ( n ) { return { times : function ( iteratee ) { // a loop } } ; } | Using a variable as an object and a function |
JS | I have a table that is created dynamically using Javascript / jQuery . The logic of which can be seen below : Before I began creating the table dynamically I was able to have both a header and footer remain in view while having the table scroll when its height became too large . I did this with the following : Although... | $ .each ( input , function ( key , value ) { let parent = $ ( ' < tr > ' ) ; let container = $ ( ' < td > ' ) .text ( 'Test ' ) ; parent.append ( container ) ; table.append ( parent ) ; } ) ; //HTML < body > < div id= '' wrapper '' > < div id= '' header '' > < /div > < table id= '' content '' > < /table > < div id= '' ... | Grid & Dynamic Table 's Height |
JS | I have a javascript that prevents right click on an HTML page : I have a < input > tag on that same page with the name `` Link '' that I want the right click to happen on.How can I achieve that ? | document.addEventListener ( `` contextmenu '' , function ( e ) { e.preventDefault ( ) ; } , false ) ; | Allowing right-click on selected class in Javascript |
JS | I have a HTML object : But for some reason ... When I access it 's top property in jQuery through the following code : Then print it using the following : It gives me this in the browser : Window { postMessage : ƒ , blur : ƒ , focus : ƒ , close : ƒ , parent : Window , … } I 'm quite puzzled on this , I even stripped aw... | < div data-x= '' 1 '' data-y= '' 1 '' class= '' tile empty '' style= '' top : 32px ; left : 434px ; '' > < div class= '' inner '' > 1:1 < /div > < /div > $ tile = $ ( ' [ data-x=1 ] [ data-y=1 ] ' ) ; top = parseInt ( $ tile.css ( `` top '' ) ) ; console.log ( top ) ; | top = $ this.css ( `` top '' ) returning an object versus element value |
JS | In https : //developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/fillthere is a line likeand I ca n't find any necessity to assign O as Object ( this ) .Is it written just for readability or is there any specific reason for assigning ? | // Steps 1-2.if ( this == null ) { throw new TypeError ( 'this is null or not defined ' ) ; } var O = Object ( this ) ; // < - WHAT IS THIS ? ? ? ? ? ? ? ? ? ? ? // Steps 3-5.var len = O.length > > > 0 ; // Steps 6-7.var start = arguments [ 1 ] ; var relativeStart = start > > 0 ; // Step 8.var k = relativeStart < 0 ? M... | I have no idea Object ( this ) means |
JS | With this debounce function : can someone explain why I should use fn.apply ( context , args ) instead of fn ( ) only ? I know .apply will change the context and var context = this will make the context always be the same as the context in fn ( ) . I ca n't find a scenario where using fn ( ) and fn.apply ( context , ar... | function debounce ( fn , delay ) { var timer return function ( ) { var context = this var args = arguments clearTimeout ( timer ) timer = setTimeout ( function ( ) { fn.apply ( context , args ) } , delay ) } } | Can someone explain the 'this ' in debounce function in JavaScript ? |
JS | I 'm currently using this RegEx ^ ( 0 [ 1-9 ] |1 [ 0-2 ] ) / ( 19|2 [ 0-1 ] ) \d { 2 } $ in .NET to validate a field with Month and Year ( 12/2000 ) .I 'm changing all my RegEx validations to JavaScript and I 'm facing an issue with this one because of /in the middle which I 'm having problems escaping.So based on othe... | RegExp.quote = function ( str ) { return ( str + `` ) .replace ( / [ . ? *+^ $ [ \ ] \\ ( ) { } |- ] /g , `` \\ $ & '' ) ; } ; var reDOB = '^ ( 0 [ 1-9 ] |1 [ 0-2 ] ) / ( 19|2 [ 0-1 ] ) \d { 2 } $ ' var re = new RegExp ( RegExp.quote ( reDOB ) ) ; if ( ! re.test ( args.Value ) ) { args.IsValid = false ; return ; } | RegEx conversion to use with Javascript |
JS | We have the options for react-graph-vis in state : We want to update options.physics.enabled and options.nodes.font with props from the parent component without removing or editing any other default options in state : Am I holding it wrong ? | { options : { physics : { enabled : false ... } } nodes : { font : “ 12px sans-serif # 888f99 ” ... } } < Graph graph= { this.state.graph } options= { { ... this.state.options , physics : { enabled : { this.props.isPhysicsOn } } , nodes : { nodes : { font : this.props.isNodeLabelShowing ? ‘ 12px sans-serif # 888f99 ’ :... | How to update multiple object children fields using the ES6 spread ? |
JS | So I 've got this JS program : http : //codepen.io/anon/pen/avgQVaI can reveal red rect by moving the grey divider to the right , but I need this divider to follow my mouse whenever I enter this block . How do I do this ? | $ ( '.divider ' ) .draggable ( { axis : ' x ' , drag : function ( e , ui ) { $ ( '.right ' ) .width ( 100 - ui.position.left ) ; $ ( '.yellow ' ) .css ( 'right ' , ui.position.left ) ; } } ) ; | Holding a mouse on enter |
JS | I got one weird issue with Date object initialization . And wondering if someone can explain why..Results : Why are these three Date objects so different ? | var exp1 = new Date ( '2014-10-17 ' ) ; var exp2 = new Date ( 2014,9,17 ) ; var exp3 = new Date ( '17 Oct 2014 ' ) ; console.log ( exp1 ) ; console.log ( exp2 ) ; console.log ( exp3 ) ; Thu Oct 16 2014 18:00:00 GMT-0600 ( MDT ) // 16th ? Fri Oct 17 2014 00:00:00 GMT-0700 ( MST ) // Why GMT -7 Fri Oct 17 2014 00:00:00 G... | Date constructors provide unexpected results when called with similar arguments |
JS | So I 'm trying to update an element in LocalStorage with JSON but I ca n't figure out what I am doing so wrong . I want to add a product and let its quantity be updated upon adding the same product again.The first time I add X product , I get the correct quantity in one element . Upon adding another X , the quantity ch... | $ ( document ) .ready ( function ( ) { // caching let $ table = $ ( `` .shoe-table '' ) ; fetch ( `` shoes.json '' ) .then ( resp = > resp.json ( ) ) .then ( data = > { let shoes = data.shoes ; let rows = [ 1 , 2 , 3 ] ; let shoeCard = `` '' ; let products = JSON.parse ( localStorage.products || `` [ ] '' ) ; console.l... | LocalStorage updating element causes duplication with JSON in JQuery |
JS | I created a `` filter '' function that receives an array of objects . Each object has an accountId property . My function is supposed to filter out objects that have a different accountId . It is , however , pushing an undefined object in there.What 's wrong with my function ? When I pass an accountId to my function th... | export const filterItems = ( myArray , accountId ) = > { let filteredItems = [ ] ; filteredItems.push ( myArray.find ( items = > items.accountId === accountId ) ) ; return filteredItems ; } [ 0 : undefined ] | JS find function pushing undefined |
JS | I 'm trying to make a simple list that shows me a div overlay for every div in the array , but I am having problems defining each div.My current java/jQuery script involves creating a div for each object in the array along with a background image ( which I am also have trouble with links . I got an online link working ... | $ ( document ) .ready ( function ( ) { displayDesign ( ) ; $ ( `` .pagesListOverlay '' ) .mouseenter ( function ( ) { $ ( `` .pagesListOverlay '' ) .hide ( ) ; } ) ; } ) ; var arrayVariableDesign = [ { name : `` object1 '' , type : '' type1 '' , company : '' company1 '' , dateYear : '' 2017 '' , dateMonth : '' 08 '' , ... | div Overlay for every div in an array |
JS | I have this codeWhat it does is that the div `` quote '' slowly fades in , stays for a few seconds and then fades out . What I want is that all this happens when the user is on the page , if you 're not in the page , the text fades in , fades out and you miss it . How can I do that ? | $ ( document ) .ready ( function ( ) { var fade_in = function ( ) { $ ( `` .quote '' ) .fadeIn ( ) ; } setTimeout ( fade_in , 2000 ) ; var fade_out = function ( ) { $ ( `` .quote '' ) .fadeOut ( ) ; } setTimeout ( fade_out , 10000 ) ; } ) ; | Trigger a event when the user is on the page |
JS | Here is my latest discovery while experimenting with JS : I stumbled on this while doing the following : Can anyone tell me why this inside the function is not exactly what was passed as the first argument to call ? Edit 1What is the difference between string primitives and String objects in JavaScript ? has been marke... | ( function ( ) { return this ; } ) .call ( 'string literal ' ) ; // = > [ String : 'string literal ' ] in V8// = > String { `` string literal '' } in FF ( function ( ) { return this === 'string literal ' ; } ) .call ( 'string literal ' ) ; // = > false | Why does ( function ( ) { return this ; } ) .call ( 'string literal ' ) return [ String : 'string literal ' ] instead of 'string literal ' ? |
JS | document.scripts returns an HTMLCollection object holding a list of all scripts in a document . Similarly , document.getElementsByTagName ( `` script '' ) returns another HTMLCollection object holding a list of all scripts in the document.I expected the following statement to be true however it 's not.What is the reaso... | document.scripts === document.getElementsByTagName ( `` script '' ) // false | document.scripts is not equal to document.getElementsByTagName ( `` script '' ) |
JS | I 'm new to jQuery and JavaScript in general . I noticed that if you insert an element via jQuery into the DOM and try to perform an action on that element later , it fails . For example : I am adding a class of `` listenToField '' to all the input elements on the page : Then when I add the second function : It does no... | $ ( function ( ) { $ ( 'input ' ) .addClass ( 'listenToField ' ) ; } ) ; $ ( function ( ) { $ ( 'input ' ) .addClass ( 'listenToField ' ) ; // second function $ ( '.listenToField ' ) .keydown ( function ( ) { alert ( 'Hi There ' ) } ) ; } ) ; | How to solve this simple jQuery issue ? |
JS | Assuming a library with a function like : But you want to update it to use a getter , like : Is there a way to make a change like this in a backwards compatible way ? So code that uses the library assuming a function does n't break ? Edit : This question is more about library evolution ( more general ) . The other one ... | class Stuff { total ( ) { return 4 ; // might be some calculation } } class Stuff { get total ( ) { return 4 ; } } stuff.total // should work with new versionstuff.total ( ) // hopefully this still works | Is there a backwards compatible way to update a library to use getters ? |
JS | I have the following command : I 'd like to add a condition to it without having to write 2 different commands so it would be something like : I 'm know the above code wo n't run , I 'm looking for a suggestion for something that would work , without having 2 different GM commands | gm ( 'input.jpg ' ) .crop ( 500 , 500 , 10 , 10 ) .write ( 'output.jpg ' , function ( err ) { if ( err ) { console.log ( err ) } else { console.log ( 'Success ' ) } } ) var overlay = truegm ( 'input.jpg ' ) .crop ( 500 , 500 , 10 , 10 ) if ( overlay == true ) { .draw ( 'image Over 0,0 750,750 overlay.jpg ' ) } .write (... | Adding if condition to Graphic Magic Command |
JS | MDN says that A for ... in loop only iterates over enumerable , non-Symbol properties.https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for ... inBut I did a simple test and it shows that even Symbol properties are iterated in a `` for ... in '' loop.What is the catch here ? What am I missi... | var symbol = Symbol ( `` test '' ) ; function Animal ( name ) { this.name = name ; } Animal.prototype = { } ; Animal.prototype.constructor = Animal ; function Dog ( breed ) { this.breed = breed ; this.name = `` Dog '' ; this.s = symbol ; } Dog.prototype = new Animal ( ) ; Dog.prototype.constructor = Dog ; console.log (... | `` for ... in '' loop JavaScript - does it include Symbol properties |
JS | The IssueI have read a couple older SO posts researching info on the anchor pseudo classes , and keep coming across confusion between `` a '' vs `` a : link '' and when and why you would use either . In the most common reason I 've seen it is often stated that `` a '' would style links likeMy QuestionsI 'm just curious... | < a name= '' something '' > | Why would you want an anchor tag that is not a link ? ( no href attribute ? ) |
JS | In a grid , I want to highlight group of cells - a rectangle shape - starting from top left cell up to the cell under the mouse position.Let 's say our grid initially looks like this : And now the user hovers with the mouse over cell number 18 . The grid should look like this now : I prefer css solution.Is is possible ... | .grid { display : grid ; grid-template-columns : repeat ( 5 , 50px ) ; grid-template-rows : repeat ( 5 , 50px ) ; gap : 5px ; } .grid-item { display : flex ; justify-content : center ; align-items : center ; background : lightgray ; } < div class= '' grid '' > < div class= '' grid-item '' > 1 < /div > < div class= '' g... | CSS Grid - Highlight cells up to the hovered cell |
JS | I am basically making a windows xp themed portfolio and I am stumped with adding tabs to my modals . I am following a tutorial ( https : //developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/Tab_Role ) and my issue is that when I call document.querySelectorAll ( ' [ role= '' tab '' ] ' ) I get nothin . Using ... | import React , { Component } from `` react '' ; import ReactDOM from `` react-dom '' ; import `` xp.css/dist/XP.css '' ; import Draggable from 'react-draggable ' ; class AboutMeModal extends Component { render ( ) { return ( < Draggable axis= '' both '' handle= '' .tabs '' defaultPosition= { { x : 40 , y : -80 } } posi... | React.js document.querySelectorAll ( ) not returning anything |
JS | I 've found some wild code on the web i do n't understand : What is [ action.subreddit ] doing ? I thought that object keys had to be strings but this appears to be an array ? I 'm hoping to understand mechanically how this code works.thank you ! | return Object.assign ( { } , state , { [ action.subreddit ] : posts ( state [ action.subreddit ] , action ) } ) | Can not understand object with array as key |
JS | ( First I 'd like to apologize if my English is bad sometimes , I 'm French , so it 's kinda difficult to explain everything in details ) I 'm working on a personal website , but i got a problem with my responsive navigation.I made a media query for screen size under 1024px . When I 'm above 1024px , I have my regular ... | < nav class= '' fixed_nav '' > < div id= '' nav_left '' > < img id= '' logo_nav '' src= '' img/mini_trombi.png '' alt= '' logo '' / > < p id= '' txt_nav '' > 123 < /p > < /div > < ul class= '' topnav '' > < div id= '' show_n_hide_nav '' class= '' responsive_link_bg '' > < li > < a id= '' top_nav_link '' class= '' nav_l... | Responsive menu issues |
JS | I 'm trying to write my own higher order function right now and I want to know how functions like map ( ) and reduce ( ) access the array they are being applied to . And not just for arrays either , but with any higher order function like toString ( ) or toLowerCase ( ) .I hope this makes sense . I 'm sure the answer i... | array.map ( ) ^^^ // How do I get this data when I am writing my own higher order function ? array.myOwnFunction ( /* data ? ? ? */ ) | How do higher-order functions like ` map ( ) ` and ` reduce ( ) ` receive their data ? |
JS | I 'm replacing t by gwhen t is not followed by the letter p using this line of code : However , the result is tpg and I was expecting tpgo . As I do n't know which letter will follow the t I need something dynamic but I do n't know what to do , any ideas ? | `` tpto '' .replace ( / ( t ) [ ^p ] /g , `` g '' ) ; | Using replace ( ) replaces too much content |
JS | i have textbox like this : when the page loads , a script is called which sets the width of the textbox . That code is as follows : where , patId2 is a dropdown list ( select tag ) . Basically what i am trying to do is setting the width of textbox same as that of the width of dropdown list.Now , if DOCTYPE is set , the... | < input id= '' patId1 '' type= '' text '' name= '' patId1 '' value= '' '' > document.getElementById ( `` patId1 '' ) .style.width = document.getElementById ( `` patId2 '' ) .offsetWidth ; | CSS can not be applied to a form element through javascript , if doctype is set |
JS | I 'm making a research form which will display differently depending on the choice of a SELECT value . I have applied some jQuery tricks after searching through here . Unfortunately , it does n't work at all . Here is my code : HTML : JavaScript : | < select name= '' options '' id= '' choice '' > < option value= '' 0 '' selected= '' true '' > Choose ... < /option > < optgroup label='ABC ' > < option value= '' 1 '' > ... DEF < /option > < option value= '' 2 '' > ... GHL < /option > < /optgroup > < optgroup label= '' MNP : '' > < option value= '' 3 '' > X < /option ... | Change visibility of forms depending on chosen option |
JS | I am pretty new to NODE.JS.I read that in node.js only single event loop ( as its single threaded ) exist.now suppose , the case is as such , end users makes requests and below piece of code is a part of module user is trying to run : As nodejs is async , event loop will call longRunningOperation and move to the next l... | ... .some code before ... ... longRunningOperation ( argumentsForLongOperation , callbackMethod ( argumentsForCallBack ) ) ; ... .some code after ... ... | how does node.js event loop remember that it needs to call back once the long running operation is complete ? |
JS | So I 've learned about hoisting , scope chains and execution context . However , I 'm not able to grasp one particular thing . Are the variable object and the global object different objects ? And , is the `` Execution Context Object '' the same as the global object ? Here 's some code that I experimented with to get a... | let variable = 0 ; function updateVar ( value ) { this.variable = value ; } updateVar ( 1 ) ; console.log ( variable ) ; // 0/* If I remove the 'this ' keyword in the updateVar ( ) function , the console logs 1.Why ? | Global Object vs . Variable Object |
JS | Why will the following snippet throw an error ? Why does n't this snippet throw an error ? Why does immediately returning the function throw an error ? Are function expressions the only case where this happens ? Why ca n't they be reassigned ? | `` use strict '' ; ( function a ( ) { console.log ( typeof a ) ; // function console.log ( a = 0 ) ; // error } ) ( ) ; `` use strict '' ; ( function ( ) { function a ( ) { console.log ( a = 0 ) ; // 0 } return a ; } ) ( ) ( ) ; `` use strict '' ; ( function ( ) { return function a ( ) { console.log ( a = 0 ) ; // erro... | Why ca n't the name of a function expression be reassigned ? |
JS | Why do map , foreach , and reduce , not use the iterator function on Symbol.iterator ? And : | class MyArray extends Array { * [ Symbol.iterator ] ( ) { for ( let x = 0 ; x < this.length ; x++ ) { yield this [ x ] *2 } } } const log = console.logconst arr = new MyArray ( 1,2,3 ) console.log ( [ ... arr ] ) // [ 2,4,6 ] log ( arr.map ( ( i ) = > i ) ) // [ 1,2,3 ] const arr = [ 1,2,3 ] Object.defineProperty ( Obj... | Why do map , foreach and reduce not use the iterator function on Symbol.iterator ? |
JS | My web page has 5 videos on it . Only when you hover over the video will it begin to play . My code for this is as follows : I have used : nth-child because if I hover over video 4 , it plays video 1 so I have to be specific . This means I have to repeat the above code for every video but change the : nth-child number ... | $ ( `` .service : nth-child ( 1 ) a '' ) .hover ( function ( ) { $ ( '.service : nth-child ( 1 ) a video # bgvid ' ) .get ( 0 ) .play ( ) ; } , function ( ) { $ ( '.service : nth-child ( 1 ) a video # bgvid ' ) .get ( 0 ) .pause ( ) ; } ) ; | Improving HTML5 video and jQuery code to be more efficient |
JS | Im making a snake game in javascript and im creating the objects and gameloops inside the window.onload function . Now Im wondering over the objects Im creating inside the function scope are efficiently used ? What is the difference between using these two kinds of declarations ? 1:2 : Im currently using the 1 : case a... | window.onload = function ( ) { ... Code ... } ; var Snake = { x : null , y : null , initialize : function ( x , y ) { this.x = x ; this.y = y } , position : [ x , y ] , move : function ( x , y ) { ... Code ... } } function Snake ( x , y ) { this.x = x ; this.y = y ; this.position = function ( ) { return [ this.x , this... | property vs var : what are the perfomance issues |
JS | I 've made a simple table in HTML , CSS and Bootstrap , and I want to change the dates that are in the cells . ( translate text ) Now for JS , i try to select the table then to add new rows and colums : That array will be the new cells so ( a1 is translate for id , b1 is translate for consulting , c1 is translate for p... | < table class= '' table table-striped '' id= '' TabelPret '' > < thead > < tr > < th scope= '' col '' > id < /th > < th scope= '' col '' > service < /th > < th scope= '' col '' > price ( Euro ) < /th > < /tr > < /thead > < tbody > < tr > < th scope= '' row '' > 1 < /th > < td > consulting < /td > < td > 50 < /td > < /t... | Translate table in pure js |
JS | I want to update state of key heart in the array 's objects when the heart icon pressed it changes to red so for this I 'm using react native icons and i 'm using heart and hearto to switch when click on ithere is the code : Here it function which is called when heart icon pressedhere is the heart icon code kindly help... | state = { localAdversiment : [ { title : `` Ecloninear 871 '' , image : require ( `` ../../assets/images/truck_image.png '' ) , year : `` 2015 '' , type : `` Truck '' , status : `` new '' , price : `` $ 2000 '' , heart : `` hearto '' } handleFavourite = index = > { const { heart } = this.state.localAdversiment [ index ... | How to setState on Object item within array |
JS | I 'm trying about ul will moving about 40px to top every second . I was trying many solutions on stackoverflow , but nothing helped.That 's my code | setInterval ( function ( ) { $ ( `` # ul_news '' ) .animate ( { marginTop : -40 } , 300 ) ; } , 1000 ) ; # ul_news { /*position : absolute ; top : 0 ; left : 100px ; z-index : 20 ; */ } # ul_news li { z-index : 20 ; color : black ; list-style : none ; padding-bottom : 50px ; } < script src= '' https : //ajax.googleapis... | SetInterval is repeating only one time . How to fix it ? |
JS | I 've been working on a library in JavaScript using p5.js for sprite rendering . I 've got an object for storing sprite information which is then added to an array that has a function that updates every frame.Then I am using this function to draw the sprites , which are added to the array in the function above.My issue... | function createsprite ( img , x , y , width , height , layer , tag ) { var sprite = { img : img , xpos : x , ypos : y , width : width , height : height , id : spriteid , clayer : layer , stag : tag , removesprite : removeobject ( this.id ) , frozen : false } ; spriteid++ ; spritesarray.push ( sprite ) return sprite ; }... | Modifying properies of in a Javascript object |
JS | I 'm having some issues with scoping in JavaScript when generating a function from within a loop . What I Want : The way I want this to work is a for loop that for each iteration , generates a function named doStuff + i . For example , the first iteration will generate doStuff1 ( ) the second will generate doStuff2 ( )... | function test1 ( ) { document.getElementById ( `` output '' ) .innerHTML = `` # 1 Output : '' ; var myFunctions = [ ] ; for ( var i = 0 ; i < 10 ; i++ ) { myFunctions [ i ] = function ( ) { document.getElementById ( `` output '' ) .innerHTML += `` < br > '' + i ; } } for ( var j = 0 ; j < 10 ; j++ ) { myFunctions [ j ]... | Variable in generated JavaScript function does n't behave as expected |
JS | I have the following string.I would like to replace dkdkd-akdoa.My replace method looks likebut it also replaces v/ . How do I replace only dkdkd-akdoa ? | /v/dkdkd-akdoa ? string.replace ( `` v\/ ( .+ ) \ ? `` , `` replace '' ) | How to select only certain part in a match ? |
JS | in my html page there are three form input has been related each other.first input as combobox with option : TCAIntaseptsecond and third input as text type.if first input fill is `` TCA '' when user input in second input `` 01 '' so in third input automaticly filled by `` 1-120 '' .if first input fill is `` intasept ''... | var interval , step ; $ ( `` # first '' ) .change ( function ( e ) { if ( this.option : selected ) interval = { // map of input value attributes to interval values `` TCA '' : 120 , `` intasept '' : 32 } [ this.value ] ; update ( ) ; } ) ; $ ( `` # secondInput '' ) .on ( `` change keyup input paste '' , function ( e ) ... | how to make function which related comboboxes option |
JS | I 'm trying to create a slider that increment this way : I first started doing a logarithmic slider but it actually did n't match the required labels . I ca n't figure out how to achieve this . Any ideas ? Complexity is that incrementation is changing during the slider progression : 5 - > 10 , 10 - > 100 , 500 - > 1000... | < html > < /html > | Complex slider incrementation |
JS | I am having an issue where after reloading a group object , it is being cropped and parts of the object are not appearing.So here is the object after grouping multiple objects together ... After I save the data and reload it , the same object loads in like this ... As I wrote this code quite some time ago , and it is q... | var json = JSON.stringify ( canvas.toDatalessJSON ( [ 'id ' , 'groupId ' , 'componentType ' , 'diametre ' , 'objectHeight ' , 'resizable ' , 'locked ' , 'view ' , 'info ' , 'pathName ' , 'color ' , 'shape ' , 'opacity ' , 'system ' , 'svgUid ' , 'format ' , 'filters ' , 'tags ' ] ) ) ; canvas.loadFromDatalessJSON ( thi... | FabricJs : parts of grouped objects are being cropped when canvas is reloaded from db |
JS | I was doing some javascript exercises online ( codewars.com ) . One problem asked the user to take an array of array objects and remove one level from the entirety of the array.I ended up learning about the concat method , but the most popular solution used this statement ... Can someone please explain the usage of [ ]... | [ ] /* becomes */ [ ] [ [ 1 , 2 , 3 ] , [ `` a '' , `` b '' , `` c '' ] , [ 1 , 2 , 3 ] ] /* becomes */ [ 1 , 2 , 3 , `` a '' , `` b '' , `` c '' , 1 , 2 , 3 ] [ [ 3 , 4 , 5 ] , [ [ 9 , 9 , 9 ] ] , [ `` a , b , c '' ] ] /* becomes */ [ 3 , 4 , 5 , [ 9 , 9 , 9 ] , `` a , b , c '' ] function ( arr ) { return [ ] .concat.... | How does using specifically `` [ ] '' as a parameter work ? |
JS | today my question is asking how I would access a function inside a function . So , for example , I have a button , and if I click it , it would alert . The thing is , if you have a function surrounding the function , the inside function with the alert would not alert.Here 's an example : html : js : so the doStuff ( ) ... | < button onclick= '' doStuff ( ) '' > Alert < /button > function nothing ( ) { var doStuff = function ( ) { alert ( `` This worked ! '' ) } } | How to access function inside of function ? |
JS | *Note : The following question is not meant to be for people 's opinion but is being asked in terms of best processing speed for the webpage , jQuery , etc.I currently have code which follows the below `` test '' code format : My question is : should the event handler ( not the event listener ) be in the same code stru... | $ ( document ) .ready ( function ( ) { $ ( '.my-class ' ) .on ( 'click ' ) { if ( $ ( '.my-class ' ) .hasClass ( 'active ' ) { $ ( '.my-class ' ) .removeClass ( 'active ' ) ; return ; } $ ( '.my-class ' ) .addClass ( 'active ' ) ; } } ) ; function toggler ( obj ) { if ( $ ( obj ) .hasClass ( 'active ' ) { $ ( obj ) .re... | JS/jQuery - Better to run event handler in $ ( document ) .ready or in called function |
JS | I have the following piece of code : Each time I click on the little icon .delete I should remove the current value and I was able to achieve that with the following code : But the code above has a problems : if I remove all the items I will end up with the following ( ) empty string and I ca n't have it so : How do I ... | < ul class= '' ul '' id= '' selected_conditions '' > < li data-field= '' asset_locations_name '' data-condition= '' in '' > < i class= '' fa fa-minus-circle delete_condition '' aria-hidden= '' true '' title= '' Click to remove this condition from the list '' > < /i > WHERE asset_locations_name IN ( < span class= '' con... | How to count the elements on deletion so I not end up with an empty ( ) ? |
JS | Can I transform string # ff00fffirstword # 445533secondword # 008877thirdword to Using regexp in javascript or actionscript3 program ? I tried the code below , but it 's not perfect ( actionscript3 code ) : If there one more # in that string , the output would not be like I want it to be . I do n't know how to write a ... | < font color= ' # ff00ff ' > firstword < /font > < font color= ' # 445533 ' > secondword < /font > < font color= ' # 008877 ' > thirdword < /font > var pat : RegExp = / ( # \w { 6 } ) ( [ ^ # ] + ) /g ; var html : String = t.replace ( pat , `` < font color=\ ' $ 1\ ' > $ 2 < /font > '' ) ; trace ( html ) ; // output : ... | transform ' # ff00fffirstword # 445533secondword # 008877thirdword ' to html tag format |
JS | I know there are a lot of resources on this , but none of them have worked for me.Some are : webgl readpixels is always returning 0,0,0,0 , and this one : https : //stackoverflow.com/questions/44869599/readpixels-from-webgl-canvas\as well as this one : Read pixels from a WebGL texture but none of them have been either ... | var capturedImageData = new Float32Array ( screenWidth * screenHeight * 4 ) ; gl.readPixels ( 0 , 0 , screenWidth , screenHeight , gl.RGBA , gl.FLOAT , capturedImageData ) ; var offscreenCanvas = document.createElement ( `` canvas '' ) ; offscreenCanvas.width = screenWidth ; offscreenCanvas.height = screenHeight ; var ... | WebGL Reading pixels properly from offscreen canvas |
JS | Consider : now x and Foo have the same prototype , but only Foo responds to .prototype : Why does n't x.prototype work , but Foo.prototype does work ? | function Foo ( ) { } var x = new Foo ( ) ; Object.getPrototype ( x ) === Foo.prototype // truex.prototype === Foo.prototype // falseFoo.prototype // Foo { } ( depending on which browser ) x.prototype // undefined | Why do functions respond to .prototype but regular objects do not ? |
JS | I have an array data , I want to filter it into two array.One if id==100 and second if id ! =100 | $ scope.if100 = $ filter ( 'filter ' ) ( data , { id : 100 } ) [ 0 ] ; $ scope.ifnot100 = ? | Angular filter if value not matched |
JS | When I type props into my React component in PyCharm , it automatically inserts a pair of curly braces . Like so ( cursor position is | ) : Becomes : I 've searched through the settings but did n't find a related setting to disable it . Does it exist ? | < MyComp className=| < MyComp className= { | } | Disable auto { } insertion for React props in PyCharm |
JS | I want color one word on a paragraph but I create this paragraph with TextNode then is display like some text.Example : | < ! DOCTYPE html > < html > < body > < p > Click the button to create a Text Node. < /p > < button onclick= '' myFunction ( ) '' > Try it < /button > < script > function myFunction ( ) { var t = document.createTextNode ( `` Hello World < span style=\ '' color : # BA0000\ '' > error < /span > `` ) ; document.body.append... | Use < span > on paragraph with createTextNode |
JS | I 'm trying to use the library https : //github.com/AnthumChris/opus-stream-decoder/I have a stream of OPUS encoded sound ( 2ch , 48kHz ) from a high quality microphone ( but I play a music in loop on it to test this ) . I know it works because I can hear it if I use : websocat -- binary ws : //third-i.local/api/sound ... | let audioWorker : any ; let exampleSocket ; let opusDecoder : any ; let audioCtx : any ; let startTime = 0 ; let counter = 0 ; function startAudio ( ) { /* const host = document.location.hostname ; const scheme = document.location.protocol.startsWith ( `` https '' ) ? `` wss '' : `` ws '' ; const uri = ` $ { scheme } :... | Sound scheduling issue when playing OPUS from websocket |
JS | I have a 3D Serpinski Triangle written in Javascript and WebGL , using a Common folder located at : https : //github.com/esangel/WebGL/tree/master/CommonEach side is supposed to have a different color . The triangle renders and spins as it should , but the problem is that the back side is transparent . I 've tried alte... | `` use strict '' ; var canvas ; var gl ; var theta = 0.0 ; var dtheta = 0.1 ; var thetaLoc ; var speed = 50 ; var bufferId ; var vertices ; var dir = 1 ; var points = [ ] ; var colors = [ ] ; var NumTimesToSubdivide = 3 ; window.onload = function init ( ) { canvas = document.getElementById ( `` gl-canvas '' ) ; gl = We... | How to fix transparent side of 3D Serpinski Triangle |
JS | Getting different results on different machines and wonder if this is expected behaviour or a potential error in implementation of ' > > > ' operation for certain CPUs ? ( undefined > > > 0 ) evaluates to 0 on other machines I tested.But , then with CPU features enabled : AVX FMA3 BMI1 BMI2 LZCNT POPCNT | Linux qemux86-64 4.18.41-yocto-standard # 1 SMP PREEMPT Tue Oct 8 20:33:31 UTC 2019 x86_64 GNU/Linuxroot @ qemux86-64 : ~ # node -- v8-options|head -n 1SSE3=1 SSSE3=1 SSE4_1=0 SAHF=1 AVX=0 FMA3=0 BMI1=0 BMI2=0 LZCNT=0 POPCNT=0 ATOM=0root @ qemux86-64 : ~ # node -v v8.12.0root @ qemux86-64 : ~ # node -e 'console.log ( u... | undefined > > > 0 == 4294967295 ? |
JS | I 'm creating a code , a part of this code uses a regular expression which is : My goal is to check if there is a repeated number.The problem arises when I use the above snippet in a larger section of code . I have the same input at the above snippet , but in the below code , the regex isnt workHere is the code : So in... | var ex = `` 122 '' , checker = / ( \d ) \1 { 1 , } /g , c = pattern.test ( +ex ) ; if ( c ) console.log ( ` works. ` ) ; function almostIncreasingSequence ( sequence ) { var clone = [ ] .concat ( sequence ) , l = clone.length , pattern = / ( \d ) \1 { 2 , } /ig ; if ( pattern.test ( clone ) ) { return false ; } var sor... | The regular expression does n't work equal in different code even being the same input |
JS | I 'm using jquery and ajax to open a bootstrap modal window . My code works perfectly when not in a loop , and my content is displayed appropriately in the modal window . But I have five modals on the page , and natually I 'd like to use a for loop so I do n't repeat my code five times.It seems like a no-brainer to wri... | var i = 1 ; $ ( ' # modal ' + i ) .on ( 'show.bs.modal ' , function ( e ) { var id = e.relatedTarget.dataset.id ; $ .ajax ( { type : 'post ' , url : 'modals/modal ' + i + '.php ' , data : { id : id } , success : function ( data ) { $ ( ' # modal ' + i ) .html ( data ) ; } } ) ; } ) ; for ( i = 1 ; i < 6 ; i++ ) { $ ( '... | `` i '' value in javascript for loop is not being recognized in a jquery function |
JS | While executing the below code in javascript : According to me , it should output : But javascript engine outputs : If we change the name of array as names , then it outputs according to expectations : name is not a javascript reserved keyword .Could you please let me know the reason for this behavior . | var name= [ `` Pankaj '' , '' Kumar '' ] ; for ( var i=0 ; i < name.length ; i++ ) { console.log ( `` Hello `` +name [ i ] ) ; } Hello Pankaj Hello Kumar Hello P Hello a Hello n Hello k Hello a Hello j Hello , Hello K Hello u Hello m Hello a Hello r Hello Pankaj Hello Kumar | Defining array in javascript and keeping the name of array as name |
JS | I have the following HTML code . I would like to find and replace the text without HTML tags and wrap it inside a p element using jQuery . Is there a way to reach my goal ? | < div class= '' col span_12_of_12 firstDiv '' > < h2 > My tasks < /h2 > Lorem ipsum dolor sit amet , consetetur sadipscing elitr < ul > < li > Lorem ipsum dolor sit < /li > < li > Lorem ipsum dolor sit < /li > < li > Lorem ipsum dolor sit < /li > < li > Lorem ipsum dolor sit < /li > < /ul > Lorem ipsum dolor sit amet ,... | How to find text without html tag and wrapp it with a p elment |
JS | JavaScript has all amounts of crazy flexibility . I decided to take advantage of it and have a function change itself on the first call . Is this a bad thing to do ? It works like this : This function is called inside of a main loop , so it gets called many times , but the instance is only ever `` supposed '' to be ins... | ( function ( ) { var nextAfter = function ( ) { } ; Something.prototype.next = function ( ) { //do pre-start actions . this.next = nextAfter ; } ; } ) ( ) ; | Wrong to have a function change the variable reference it was called from ? |
JS | I am trying to create a keyup event handler that checks the first text box so that when enter is released , it calculates the number hours worked by the user input . If the user enters a number LESS THAN 40 it takes that input and multiplies it by $ 12 , but if the user enters a number more than 40 ( hours ) , it takes... | let hours = document.getElementById ( `` box1 '' ) let pay = document.getElementById ( `` box2 '' ) document.addEventListener ( `` keyup '' , press ) ; function press ( ) { if ( event.key === `` Enter '' ) { let a = hours.value ; if hours.value < = 40 ; let b = ( a * 12 ) ; else hours.value > = 40 ; let c = [ ( ( a - 4... | Using KeyUp , how do I get a value after the enter key is released ? |
JS | I 've read some related question regarding my problem but I still ca n't figure it out . So I decided to ask now . I 'd like to know if there is something wrong with my code . Basically , the data in the input boxes should get into the database ( MYSQL ) but everytime I click the submit button , nothing is happening.Co... | < ! DOCTYPE html > < ? phpinclude ( `` includes/db.php '' ) ; ? > < html > < head > < /head > < script src= '' //cdn.tinymce.com/4/tinymce.min.js '' > < /script > < script > tinymce.init ( { selector : 'textarea ' } ) ; < /script > < body bgcolor= '' # aad6bb '' > < form action= '' insert_product.php '' method= '' post... | Data not getting into MySql Database |
JS | I 'm not sure if I phrased the question title correctly ; please consider the following to clarify ... How would I go about having access to this within the methods / props of foo but having this refer to the initial object aka e and not foo ? The best that I have come up with is thisWhat I have currently works but I a... | ( function ( ) { var foo = { bar : function ( ) { // Is it possible to reference 'this ' as the // initializing 'object ' aka ' e ' and not 'foo ' ? // The easy part , currently because 'this ' refers to 'foo ' , // is returning 'this ' aka 'foo ' so that chaining can occur return this ; } , other : function ( ) { retu... | Extending inheritance of ` this ` to methods / properties of an ` object ` |
JS | I 'm very new to coding . I 'm trying to create a page with 4 columns that will display different title and description each day of the week.For example , on Monday display 4 titles and descriptions and on Tuesday display other values ... and so on.I have searched the web for an approximately a week now but I ca n't fi... | var today = new Date ( ) ; if ( today.getDay ( ) == 1 ) document.getElementById ( `` text '' ) .innerHTML = ; else if ( today.getDay ( ) == 2 ) document.getElementById ( `` text '' ) .innerHTML = ; else if ( today.getDay ( ) == 3 ) document.getElementById ( `` text '' ) .innerHTML = ; else if ( today.getDay ( ) == 4 ) ... | 4 columns that displays different content each day of the week |
JS | I have input field with id txt1 but I am unable to change the value from JavaScript.Note : I find on stackoverflow how to change input value but could not found any answer . Title of the question save lot of time . It is valid question in this way . | < form action= '' '' > First name : < input type= '' text '' id= '' txt1 '' onkeyup= '' showHint ( this.value ) '' > < /form > < script > document.getElementById ( 'txt1 ' ) .value ( 'anyvalue1111 ' ) ; < /script > | how to set value in input by JavaScript ? |
JS | I have a very strange problem in jQuery/CSS an I 'm not sure what 's is going wrong here . Consider this minimal example : View the code ( fiddle here ) in Chrome and click on one of the list buttons . Nothing happens . But , if you unfocus the window , it suddenly activates the class and the red color is rendered.It s... | # list li { color : # 3c6174 ; cursor : pointer ; } # list li.active { color : red ; } < ul id= '' list '' > < li class= '' active '' > < /li > < li > < /li > < li > < /li > < /ul > $ buttons = $ ( `` # list li '' ) ; $ buttons.click ( function ( ) { $ buttons.removeClass ( `` active '' ) ; $ ( this ) .addClass ( `` ac... | Font color by classes on li are not rendered until unfocus in Chrome |
JS | I have an array that looks like this , how can I sort it alphabetically without loosing the key ? | var items = [ { 11 : 'Edward ' } , { 12 : 'Sharpe ' } , { 13 : 'Alvin ' } ] ; | Another javascript array alphabetical sorting hardtime |
JS | Team , I received syntax error when using function ( ) { } , but not when ( function ( ) { } ) , why ? I know ( function ( ) { } ) is still declaration ' ( function ( ) { } ) ( ) ' is the expression . But why this declaration is not possible with simply function ( ) { } without covering with ( ... ) ? | < html > < body > < script > function ( ) { } //**Syntax error** ( function ( ) { } ) //Declaration ( function ( ) { } ) ( ) //Expression ; so executed. < /script > < /body > < /html > | function ( ) { } and ( function ( ) { } ) in javascript |
JS | I am trying to create a simple page where you click and can create rectangles on a canvas . It takes the user 's mouse clicks as input , and then creates a rectangle from the x and y of the click . However , it places the rectangle off to the side by some amount , and I am not sure why.Fiddle : https : //jsfiddle.net/2... | < canvas id= '' cnv '' > < /canvas > # cnv { width:99vw ; height:98vh ; background-color : # faefbd ; } $ ( function ( ) { var canvas = $ ( ' # cnv ' ) ; var canvObj = document.getElementById ( 'cnv ' ) ; var ctx = canvObj.getContext ( '2d ' ) ; var point1 = { } ; var point2 = { } ; canvas.click ( function ( e ) { cons... | Why are the rectangles I am creating on this canvas not getting put in the right spot ? |
JS | I 've got to be able moving through an array forwards and backwards . Endlessly and without getting an index out of bounds-exception . For moving forward I 've known an elegant way using the modulo-operator . For the backwards moving I 've had to figure out something myself.Here 's my solution : It works . But is there... | const inc = document.getElementById ( `` inc '' ) ; const dec = document.getElementById ( `` dec '' ) ; const arr = [ `` One '' , `` Two '' , `` Three '' , `` Four '' , `` Five '' , `` Six '' ] ; let i = 0 ; inc.addEventListener ( `` click '' , ( ) = > { i = ( i + 1 ) % arr.length ; console.log ( arr [ i ] ) ; } ) ; de... | Endlessly moving through an array backwards |
JS | I have a standard email which I am looking to extract certain details from.Amongst the email are lines like so : So to simulate this I have the following JavaScript : This only comes out with one result , which is : I was hoping to get the capture group ( [ ^\ < ] * ) which in this example would be John SmithWhat am I ... | < strong > Name : < /strong > John Smith var str = `` < br > < strong > Name : < /strong > John Smith < br > '' ; var re = /\ < strong > Name\s* : \ < \/strong > \s* ( [ ^\ < ] * ) /gmatch = re.exec ( str ) ; while ( match ! = null ) { console.log ( match [ 0 ] ) ; match = re.exec ( str ) ; } < strong > Name : < /stron... | Regex Group Capture |
JS | I want to animate a translateX with transition on a click event by adding a class to the div in the js . The transform and transition properties are added in the css file.It only works if I query the width property of any element in the dom before adding the class.here is a jsfiddle : https : //jsfiddle.net/5z9fLsr5/2/... | var widget = document.getElementById ( 'widget ' ) ; widget.style.display = 'block ' ; document.getElementById ( 'widget2 ' ) .clientWidth ; //comment this line out and it wont workwidget.className = 'visible ' ; | Transition not working without querying width property |
JS | Write a program that predicts the approximate size of a population of organisms . Use the following data : Starting number of organisms : 2 Average daily increase : 30 % Number of days to multiply : 10 The program should display the following table of data : My code is not outputting the same Approximate Population . W... | Day Approiximate Population1 22 2.63 3.384 4.395 5.716 7.427 9.658 12.549 16.3110 21.20 var NumOfOrganisms = 2 ; var DailyIncrease = .30 ; var NumOfDays ; for ( NumOfDays = 1 ; NumOfDays < = 10 ; NumOfDays++ ) { calculation ( NumOfOrganisms , DailyIncrease , NumOfDays ) ; } function calculation ( organisms , increase ,... | My javascript output does not match the expected output . I do n't know where I went wrong |
JS | I found a bug in a program I had written , but the behavior of the error is inexplicable to me : If I have : And then use this selector : I see this : What I 'm surprised by is the fact that the eq ( 0 ) selects the first input even though I explicitly tell it to find only ones with name=phone [ ] Here is a fiddle : ht... | < input type= '' text '' name= '' cust_id '' value= '' 666 '' / > < input type= '' text '' name= '' phone [ ] '' value= '' 666 '' / > var test = $ ( `` input [ name=phone [ ] ] : eq ( 0 ) '' ) ; test.css ( `` color '' , `` red '' ) ; | jQuery eq function unexpected behavior |
JS | Some keyboard `` chords '' ( combinations of keys pressed simultaneously ) will not register properly in the browser ( Chrome and Firefox tested ) . For example , with the code below , try this:1 ) press the `` e '' key ( it will log `` key 69 '' ) 2 ) while holding down `` e '' , press `` ] '' ( it will log `` key 221... | document.onkeydown = function ( event ) { var key = event.keyCode ; console.log ( `` key '' , key ) ; } ; | Some `` chords '' do not work with onkeydown ( JavaScript ) |
JS | I 'm studying on how to use bootstrap datepicker but i need it to show only the months or year just like this : but the result only became like this : I only need to pick the month and the year not the whole calendar.Below is my whole code snippet : | $ ( document ) .ready ( ( ) = > { $ ( `` # datepicker '' ) .datepicker ( { format : `` mm-yyyy '' , startView : `` months '' , minViewMode : `` months '' } ) ; } ) < html lang= '' en '' > < head > < meta charset= '' UTF-8 '' / > < meta name= '' viewport '' content= '' width=device-width , initial-scale=1.0 '' / > < met... | Boostrap Datepicker - months and year only does n't work |
JS | How do I access the second number `` 19 '' , which is in the Numbers array in the following JSON ? I 've tried every which way and have not been able to . | { `` Numbers '' : [ { `` 1 '' : 6 } , { `` 2 '' : 19 } , { `` 3 '' : 34 } , { `` 4 '' : 38 } , { `` 5 '' : 70 } ] , `` MB '' : 5 , `` MP '' : `` 05 '' , `` DrawDate '' : `` 2016-03-22T00:00:00 '' } | access the values form the following JSON |
JS | Collection of my database is something like belowI need to group it by `` day '' .The result which I wantI am not getting the actual result which I want any help will be highly appreciatedI had try with this but wo n't get an idea how i will get salesOfActive and salesOfInactive per day | [ { _id:1 , status : '' active '' , sale : 4 , createdAt : '' 2019-10-08 08:46:19 '' } , { _id:2 , status : '' inactive '' , sale:5 , createdAt : '' 2019-10-08 06:41:19 '' } , { _id:2 , status : '' inactive '' , sale:5 , createdAt : '' 2019-10-08 02:01:19 '' } ] [ { createdAt : '' 2019-10-08 02:01:19 '' , inactive : 2 ... | MongoDB group aggregation with condition in $ sum |
JS | I am writing an algorithm for iterating over the elements of an array at a given speed . I use this to iterate through the cells on the game map in an array of paths that I find.I need that when a new function is called with a new array , the last function call stops working.This will be used to move along the path , a... | let coord = { x:0 , y:0 } let goByPath = ( path= [ ] , coord= { } ) = > { let i = 0 ; pathIteration ( i , path , coord ) } let pathIteration = ( i , path , coord ) = > { if ( i++ < path.length ) { setTimeout ( ( ) = > { coord = path [ i-1 ] ; console.log ( coord ) ; pathIteration ( i , path , coord ) ; } ,500 ) ; } ret... | Game walk by path in array |
JS | I want to make a gradual blur transition in an html image using JS . I 'm using an initial style , then updating the style property using document object and a global variable.But the following code does n't update anything : | var val = 8function adjust_blur ( ) { document.getElementById ( `` image '' ) .style.filter = blur ( String ( val ) + `` px '' ) val -= 1 ; } function update_blur ( ) { window.setTimeout ( adjust_blur , 1000 ) } # image { filter : blur ( 1px ) ; max-width : 600px ; } < img src='https : //image.freepik.com/free-vector/m... | Changing CSS properties in javascript |
JS | I want to make unique instances of a set of cars that different people can hold . The cars will have similar base specs but some of their properties and methods will vary.The problem I have is that I ca n't work out how this should work . How do you deal with or create instances of instances in JavaScript ? This causes... | var Car = function ( make , country ) { this.make = make ; this.country = country ; } ; var Ferrari = new Car ( 'Ferrari ' , 'Italy ' ) ; var fred = new Person ( ) { } ; var fred.cars [ 'Ferrari ' ] = new Ferrari ( 1200 , 300000 ) ; Uncaught TypeError : Ferrari is not a constructor var Ferrari = function ( currentPrice... | How do you create an instance of an instance in JavaScript |
JS | I have a simple search function that I use on a table of information , but since I turned the text in the table into editable fields the search function is n't working anymore.I tried to troubleshoot it in a few different ways , but ca n't seem to get it working.Here 's what I have got so far : This works just fine on ... | var $ rows = $ ( '.list # data ' ) ; $ ( ' # search ' ) .keyup ( function ( ) { var val = $ .trim ( $ ( this ) .val ( ) ) .replace ( / +/g , ' ' ) .toLowerCase ( ) ; $ rows.show ( ) .filter ( function ( ) { var text = $ ( this ) .text ( ) .replace ( /\s+/g , ' ' ) .toLowerCase ( ) ; return ! ~text.indexOf ( val ) ; } )... | Search function on ( disabled ) input fields |
JS | I was reading a JavaScript book and I was reading how you can extend the arrays functionality of JavaScript array by prototype , then I came to this example that I could not understand , and there was no deep explanation of it , and Iam not able to understand that : here I was able to access the arguments , but i do n'... | Array.prototype.some_function = function ( ) { var args = this.some_function.arguments ; // 1 var args_length = this.some_function.arguments.length ; // 2 ... } // some_function this.some_other_function.arguments // gives error | arguments property can be access by this.some_function.arguments ? actually i m not able to explain ? |
JS | I want to programmatically fire the `` end '' event of d3-drag.I have some circles and have the drag-handling of them implemented like so : Now , later in my code , I would like to trigger the `` end '' part of this programmatically.I have already tried something like this : | ... .call ( d3.drag ( ) .on ( `` drag '' , function ( ) { ... } ) .on ( `` end '' , function ( ) { ... } ) ) d3.select ( `` # myID '' ) .dispatch ( `` end '' ) ; d3.select ( `` # myID '' ) .dispatch ( `` dragend '' ) ; d3.select ( `` # myID '' ) .call ( d3.drag ( ) .dispatch ( `` end '' ) ) ; | Dispatching drag-end event |
JS | I 'm creating a API and I need to create a Route like api/v1/status , to see the status of the server and returns me a json with the number of the requests executed to the API since it is active , but I do n't know how to do that with NodeJS , any help ? I have that statusRoutes.js : src/routes/statusRoutes.jsIn my api... | // Initialize express routerlet router = require ( 'express ' ) .Router ( ) ; // Set default API responserouter.get ( '/status ' , function ( req , res ) { //Here is the return number of requests res.json ( { status : 'API Its Working ' , message : 'Welcome to User-Register crafted with love ! ' , } ) ; } ) ; module.ex... | Number of requests until last reset |
JS | Lets say I have a Dog constructorAnd I have an instance of that constructorAs far as I learned recently , there are two ways to check if myDog is an instance of Dog:1.2.My question is , what are the differences between the two , which one is better and why ? Thanks in advance . | function Dog ( name ) { this.name = name ; } const myDog = new Dog ( 'Charlie ' ) ; console.log ( myDog instanceof Dog ) //true console.log ( myDog.constructor === Dog ) //true | What 's thedifference between comparing object.constructor to its constructor and instanceof ? |
JS | I have two arrays and need to fill the missing values with NA by comparing the levels present in other array . I used the arr.find to search but not sure how to proceed further.Input : Output : Code : | const levels = [ 1,2,3,4 ] const arr = [ { `` LEVEL '' :1 , '' NAME1 '' : '' JACK '' } , { `` LEVEL '' :3 , '' NAME1 '' : '' TOM '' } ] out = [ { `` LEVEL '' :1 , '' NAME1 '' : '' JACK '' } , { `` LEVEL '' :2 , '' NAME1 '' : '' NA '' } , { `` LEVEL '' :3 , '' NAME1 '' : '' TOM '' } , { `` LEVEL '' :4 , '' NAME1 '' : ''... | Find Missing levels and fill it |
JS | I am newly learning jQuery and java script , currently i am facing a problem in showing the hidden button , my html isJquery : css : Also i tried using find , nextAll , closest also nothing worked so how to make this work.Demo Here | < span style= '' float : left ; padding-right:10px '' > < input type= '' button '' value= '' image '' class= '' delete '' / > < a href= '' /media/image '' > < img src= '' /media/image '' / > < /a > < /span > < span style= '' float : left ; padding-top : 5px ; '' > < a href= '' /media/image '' > < button type= '' submit... | traverse button from span to span |
JS | I have following javascript that I came across . I do n't understand the process flow of the code execution.The output that I thought would be was , 'ap ' then 'ap'.But I get 'ple ' and then 'ap'.How is this happening ? | var val = 'ap ' ; function func ( ) { if ( ! val ) { var val = 'ple ' ; } console.log ( val ) ; } func ( ) ; console.log ( val ) ; | understanding following javascript code |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.