Posts by Sergio • 133,294 points
2,786 posts
-
1
votes1
answer92
viewsA: How to create gift without javascript?
The explanation of DOM (in Portuguese) na MDN is good. Taking excerpts from there: The Document Object Model (DOM) is a programming interface for HTML, XML and SVG documents. [...] Although DOM is…
-
1
votes1
answer194
viewsA: How to go through the brother elements with jQuery?
Uses the event.target to know what the current element is, and always iterate the collection. Then with a return false; make the loop stop. Suggestion: var estrelas = $('.estrela'); estrelas.on({…
-
1
votes1
answer563
views -
2
votes1
answer95
viewsA: Use of keys to display javascript
These frameworks compile HTML and insert what is inside {{ }} in HTML. This is done differently from framework to framework. This can be very complex and from the outset needless to re-invent.…
javascriptanswered Sergio 133,294 -
7
votes1
answer1874
viewsA: What are the differences between properties and attributes in HTML?
To understand the difference it is necessary to take into account that HTML and Javascript are different languages. Thus: HTML has elements with attributes Javascript has objects with properties The…
-
6
votes1
answer7242
viewsA: Difference between Promise.then( sucess, error ) and Promise.then() . catch()?
In general terms I would say so: uses .catch() 1 time per chain of files, to catch unforeseen errors uses the error function locally to correct errors and allow chaining to continue I will give two…
-
2
votes2
answers101
viewsA: Error Nodejs and when to use "=>"
If you use Arrow functions you can’t use the reserved word function, as you initially had in the question. What’s more, the version 0.10.xx node does not support Arrow functions, the full support is…
-
2
votes1
answer465
viewsA: How to view data from a Node.js script in an HTML page
There are some crawlers on NPM/Github, one of them the simplecrawler that I use. A script I use is: var domain = 'http://teu.dominio.com/'; var Crawler = require("simplecrawler"); var fs =…
-
1
votes2
answers1903
viewsA: Add values with jquery, string to number
You’re using numbers in format String, you need to convert to Number. A suggestion, using a function that allows N arguments: var a = 6547.5; var b = 1345354.0054; var c = 2.0; function somar() {…
-
2
votes2
answers1028
viewsA: Create object with internal object array
You can choose objects or classes, it depends a little if you want something passive or active. That is, if you only want to group data, an object serves well; if you want each object to be able to…
javascriptanswered Sergio 133,294 -
4
votes1
answer592
viewsA: CSS attribute in innerHTML, how to use?
You have to choose whether to use the jQuery API or native Javascript. With jQuery you can pass a function on second argument of the method .css() and give value depending on the html of the…
-
4
votes2
answers110
viewsA: Doubt with loop of repetition
This is a case of "trailing...", you can use a function to join array elements with the sign you choose. O join or the implode do that: <?php $fator1 = isset($_POST['fator1']) ? $_POST['fator1']:…
-
4
votes2
answers302
viewsA: Is it possible to add the td values using querySelectorAll?
Yes perfectly possible. Notice you had an error in the dial, missing one . in '#tblEditavel vlr', and #tblEditavel html. And if you’re not using input you need to use `innerHTML. You could do it…
javascriptanswered Sergio 133,294 -
7
votes3
answers1993
viewsA: Exchanging TAG with Javascript
Changing the widget itself is not possible. But you can change the HTML if you don’t need event headphones. You can do it with a few steps: creates a new element put it before the element you have…
-
2
votes1
answer46
viewsA: Problem with Javascript Method Return
It is not possible to do return of that function because it is asynchronous. What you have to do is chain functions. I mean, if you have a function that needs that result, you have to call it, pass…
-
2
votes1
answer79
viewsA: Classes in Javascript
The reason is organization and ease of code reading. There is another possibility, which is not present in your code, which is to create "private methods", ie methods that the class can use…
javascriptanswered Sergio 133,294 -
21
votes1
answer3438
viewsA: var, const or Let? Which to use?
Short version: When should I wear: var: never again const: whenever possible let: when the variable needs to be overwritten Long version: Ecmascript version 6 brought with it new commands to declare…
-
3
votes4
answers1488
viewsA: How to do <li><div class="class" onclick="window.Location='link';"></div> open in new tab?
The attribute target is for anchors and does not work on elements div. You must use <div><a target="_blank" href="o-teu-link.com">texto</a></div> which is the correct…
-
2
votes4
answers5283
viewsA: Separate an array into groups?
You can check if each group has the right size and inside this if make the whole logic to change group and start the new already with the first element. A suggestion could be so: function…
-
5
votes3
answers1302
viewsA: receive two houses after the comma
You can use the .toFixed(), a method of numbers, which does two things: sets the number of digits in the decimal part turns a number into string for the zeroes to hold console.log((7.5).toFixed(2));…
-
8
votes1
answer163
viewsA: jQuery doubt append appendTo inject HTML
In that case you can use the .wrap() thus: $(".o-teu-conteudo-existente").wrap("<div class='nova-div'></div>"); That way jQuery changes the content into this new div.…
-
0
votes2
answers174
viewsA: How to classify letters and numbers in Javascript and Lodash?
That I know of lodash ago sort by keys, but not by content. To separate numbers and letters I suggest starting in two array, organizing each one and then joining them. It could be something like…
javascriptanswered Sergio 133,294 -
0
votes1
answer938
viewsA: How to update properties in React "setState"
The problem is that the this inside the callback of the axios is no longer your component. You have two alternatives: use Arrow functions use an alias With Arrow Function: mute…
-
3
votes2
answers400
viewsA: Pass javascript parameter to a php page by a button
Your code is incomplete, I don’t see where your function is confirm_delete and the selector $('apagar') is wrong. Even if it were $('#apagar') would be wrong because of event delegation and because…
-
2
votes2
answers92
viewsA: Sum of values with javascript, error?
I changed your code to make it simpler, mainly because you can make a selector with :checked so you don’t need the loops. function selecionaDactes() { var selecionados =…
javascriptanswered Sergio 133,294 -
3
votes1
answer279
viewsA: How to pass sentences to a variable and then display randomly
You must have those phrases in props or in the state component. If this is the case, to avoid duplicating code you can do so: constructor(props) { super(props); this.state = { frases: [ {title:…
-
1
votes2
answers321
viewsA: Sometimes jquery does not work
If $(".js-toggle-seguir") is the button itself so within this function the this is the button clicked. And you can use: $(".js-toggle-seguir").click(function (e) { var button = $(this); or directly…
-
12
votes3
answers4840
viewsA: How to Format Javascript Date by Naming the Month and Day of the Week
You must have kept the names of the days of the week and the month. Having this is easy: var meses = [ "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro",…
-
2
votes1
answer3741
viewsA: How do I convert formdata to json?
The idea of Formdata is to be impervious to attempts to manipulate data on the client’s side. That is, when you insert something inside, you can’t take it out. If that’s enough, use FormData, this…
-
1
votes1
answer22
viewsA: bug Multiply Coins flip jquery
You’re using id when you should be wearing class. You can only have one element per page with a die id. If you change to class it’s gonna work fine. jQuery(document).ready(function($) { var…
-
0
votes1
answer82
viewsA: How do you associate a calculus function within an express function to use in Routes?
Just change the data here: .then(data => { res.status(200).json(data); }) The end result could be just like this: .then(data => { var processado = minhaFuncao(data);…
-
6
votes3
answers2407
viewsA: State and City Combobox associative array in Javascript
Two suggestions: creates a role for you to reuse code creates an object where keys are the names of the states, so everything is organized and dependent on the JSON structure So JSON can grow and…
-
4
votes1
answer408
viewsA: How to extract space-separated words via Javascript
Using Regexp: var texto = "Eu quero tirar minhas duvidas sobre Javascript"; var palavras = texto.match(/[^\s]+/g); console.log(palavras); Using .split(): var texto = "Eu quero tirar minhas duvidas…
-
8
votes1
answer158
viewsQ: How to use deep-Learning to parse forms with addresses?
I have an app I need to import personal data into. I often receive excel or csv/txt files with fields such as name, address, email, phone, etc... File formatting varies, order also, and sometimes…
-
1
votes1
answer52
viewsA: Typeerror: obj is not defined access error and an array
I think your problem is this line (which appears twice): for (var i = 0;i <= this.obstaculos.length; i++) { You can’t use <= array.length to traverse arrays, this is because if the array has…
-
1
votes1
answer177
viewsA: Help with Javascript filter
The problem is that the array value was being overwritten in hotel.quarto[0].quartoUh = hotel.quarto[0].quartoUh.filter(.... Using var filtrados = json.hotelPesquisa.filter(function(hotel) { var…
-
1
votes3
answers268
viewsA: Use HTML in PHP
If you use double quotes to define the string, you need to use single quotes in the middle or escape them: echo "algo \"algo dentro de aspas\" algo"; or echo "algo 'algo dentro de aspas' algo"; In…
-
2
votes3
answers5502
viewsA: Remove TAG with Javascript
The native method for this is .removeChild() and must be called by the father of the element, because as you mentioned the .remove() is not supported by IE. It does exist in the jQuery API, if…
-
2
votes1
answer538
viewsA: Browse Objects from Objects
Here is a suggestion: function criarSubPasta(obj, parent) { // criar <li>nome</li> var nameLi = document.createElement('li'); nameLi.innerHTML = obj.name; parent.appendChild(nameLi); //…
-
0
votes1
answer76
viewsA: Folder Size - File System
This in Node.js is not very simple. There are other platforms that are "more specialized" in the file part. But somehow it stays here, the idea is to go read a board and at each entry of this board…
-
2
votes2
answers42
viewsA: Using object property when declaring it in javascript
You have to change, or take into account, two things in your code to make it work: within that object the functions will run in the context of itself. This means that you can use this to access the…
-
2
votes1
answer276
viewsA: How to filter a json object with jQuery?
Analyze where the array you want to filter is and what the comparison element is. From there the logic is the same as this other question/ your answer. In this case you need to repeat the logic…
-
2
votes2
answers1541
viewsA: how to filter a json object?
By your JSON I see that you have the prices in String. you have to convert to number and then use .filter() to remove the ones you don’t want. You can do it like this: var json = { "acao":…
-
4
votes1
answer940
viewsA: How to split code into multiple modules?
The way the n is inaccessible to other modules and n behaves as private variable module. This is very useful in many cases. If you want to consult the n you have to make a getter that could be so:…
-
1
votes2
answers57
viewsA: When I try to make a canvas not error but also does nothing
Some mistakes: in that file I don’t see the script for Modernizr the .addEventListener that will call your function is within the function itself, ie will never be called corrects the syntax of…
-
2
votes1
answer100
viewsA: How to use Random script
The Math.random() gives you a decimal number between 0 and 1. To have a number between 0 and 2 you can do Math.random() * 2, ie maximum is 2 minimum is 0. To have only integers (to use as array…
-
2
votes1
answer51
viewsA: Improvements in dynamic content
In relation to .live() just change to .on() and you can already use newer versions of jQuery. Regarding copy/create content you can use .clone() to exactly copy what you want. There is still…
-
1
votes1
answer307
viewsA: Only open prompt if you click the parent element and not the child element
There are two options: add a e.stopPropagation(); to prevent the event from spreading. document.addEventListener('click', function(e) { if (e.target.nodeType == 1 &&…
-
1
votes1
answer243
viewsA: Shoot event or press mouse button
In that case you can use the "mousedown" in time of "click". So when the mouse is pressed it runs the callback. If you want tablet support join also the touchstart. The code could be like this:…
-
0
votes3
answers292
viewsA: How to use a two-dimensional array with Javascript (jquery)?
If I understand correctly you want to combine the results by grouping them together nome_grupo. Example with your JSON: var result = [{ "id_rotina": "7", "treino": "treino-b", "grupo_id": "2",…