Posts by Sergio • 133,294 points
2,786 posts
-
0
votes2
answers380
viewsA: Event.preventDefault() conflicting on Contact Form
When you use event.preventDefault(); form does not send. That is, ajax runs only by calling the url url: $(this).attr('action'), data-free... What you should do is send the form data with ajax. And…
-
2
votes2
answers220
viewsA: Regex: Open and close with the same character and allow more than one type
You can use \1 to ensure the use of the same character as in a capture group. Thus, define some "limiters" at the beginning of the string, and at the end use \1 to make sure you have the same: var…
-
3
votes2
answers544
viewsA: Error starting nodejs+Sequelize+mysql project
Cannot find module 'sequelize' means he can’t find the module sequelize. Tests install with: npm install --save sequelize…
-
4
votes1
answer1348
views -
3
votes1
answer104
viewsA: What does that expression mean?
This is very typical of Mustache, a template language that compiles HTML pata. The Javascript version (Mustache.js) has an example in the documentation: View: { "person": false } Template: Shown.…
-
3
votes2
answers6031
viewsA: How does . Closest() work in Jquery?
Notice that the element where you tied the event headphone is $('tr').click, namely a tr. The Closest does a search but starting with itself. In the documentation says: Matches the selector by…
-
2
votes2
answers1366
viewsA: How to check if a DIV has an ID
The ID is an HTML attribute, so there are several ways to check. Use the one that is most useful: .attr() Using the getter of jQuery attributes: if ($('.menu').attr('id')) { // ele tem ID } else {…
-
1
votes1
answer563
viewsA: Take value and date attr of related element jQuery
Forehead to wear var data = $(this).closest('div').prev().find('.acess_prazo_date').val(); if there are several inputs in each .row, or if there is only 1: var data =…
-
0
votes1
answer43
viewsA: Ajax problem while consuming asmx
For the example you gave myData is an array thus within this cycle for you must access the element you want to iterate, that is using its index. Edit I just saw your comment: stands alert(typeof…
-
3
votes1
answer60
viewsA: Are callback functions asynchronous, only with special methods like setTimeout?
Which methods are executed asynchronously? Beyond the setTimeout that you mentioned there is the setInterval, calls ajax/xhr, Promises, async/await and all past functions to event headphones. In…
javascriptanswered Sergio 133,294 -
1
votes1
answer604
viewsA: What alternative mode could be used to block the click effect on an HTML element?
You can create a div#bloqueador inside #lista, and then the CSS you need would be: #lista { position: relative; } #bloqueador { position: absolute; top: 0; left: 0; width: 100%; height: 100%;…
-
1
votes1
answer26
viewsA: How can I remove every link that points to a video after the video ends?
Usa el[i].parentNode.removeChild(el[i]); instead of delete el[i].item(0); var vid = document.getElementById('player'); var link = document.getElementById('lista').getElementsByTagName('a'); var el =…
-
3
votes1
answer62
viewsA: Validation does not work jquery
You have to put the <script> after HTML, so jQuery cannot find the button since its HTML has not yet been read. Note also that: your tag script loading jQuery has to be closed, missing the…
-
2
votes1
answer87
viewsA: Transforming clicks into JS function
If I understand correctly you want to apply the DRY idea in this code to avoid repetition. A useful thing, if you are using different Ids and with a number to distinguish each element is to use the…
-
2
votes1
answer2688
viewsA: Dropdown with jQuery
You can change your logic a little bit to make sure he looks for others dropdown and not only the. It could be so: (jsFiddle) $(document).click(function(e) { var target = e.target;…
-
0
votes1
answer50
viewsA: Return sum objects of an array in one
You have many ways, suggestions: Creates a new object with a for: var players = [{ name: "Batman", id: "1", points: 10 }, { name: "Superman", id: "2", points: 10 }, { name: "Batman", id: "1",…
-
1
votes2
answers835
viewsA: Scroll event
Usa window.pageYOffset to know the position of the scroll, the document.scrollTop should be document.documentElement.scrollTop 'cause it’s an element method, and it’s not gonna get you what you…
-
0
votes1
answer213
viewsA: Popular inputs with jquery and insert table rows at the same time
The problem is that only the input[name="matBusca[0]"] will react to blur because when the line $(document).on('blur', 'input[name="matBusca['+ x +']"]' ,function(){ is read the x has the value of…
-
1
votes1
answer238
viewsA: Compare value of Div
Yes you can. With $('td').find('div'); you have a collection with the elements, and to have an array/collection with its values you can do so: var valores = els.get().map(function(el) { return…
-
1
votes1
answer103
viewsA: How to resolve html rendering with VUE?
In Vue.js 2 you have to use the v-html that takes the variable that has the HTML you want to use: var data = { "content": { "rendered": "<P>Bem-vindo ao WordPress. Esse é o seu primeiro post.…
-
7
votes6
answers300
viewsA: How do I transform an array that is in a string for javascript array?
That string you have looks like a JSON, a representation on String of an array, so you can use JSON.parse() to transfer it to an array. There is however a problem... ' is not valid as a string…
-
1
votes2
answers781
viewsA: Slow reaction when opening graphical dependencies
looks like you don’t have the yarn installed. The yarn is an alternative to npm, or is an engine to fetch components that are in npm. You have to install globally: npm install -g yarn…
-
4
votes2
answers443
viewsA: Remove element by clicking the jquery link
The best is to use the .closest() which returns only one element, the .parents() returns all ancestral elements. That is, if you have tables within tables or .parents() will return several tr and…
-
1
votes1
answer75
viewsA: Unexpected behavior in asynchronous javascript
This library allows you to set the maximum number of connections when using pool. If you do not specify a value the maximum is 10 as documented: connectionLimit: The Maximum number of Connections to…
-
1
votes1
answer44
viewsA: How to load js style google Analytcs
If you organized this code minificado would be like this: (function(w, d, s, l, i) { w[l] = w[l] || []; w[l].push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' }); var f =…
-
2
votes1
answer174
viewsA: React class constructor error
The difference is that one is Javascript valid in ES5 and another is code ES6. In other words, at the beginning when React was launched it used a lot of code compatible with ES5 (Ecmascript 5) and…
-
2
votes1
answer453
viewsA: How do I check with nodejs if a table is out of records?
Checks the .length of the result: db.query('SELECT * from tabela', (err, res) => { console.log(err, res, res.length); // deve dar null, [], 0 if (res.length == 0){ console.log('A tabela está…
-
2
votes3
answers1988
viewsA: disable button per second with jquery
Puts the whole logic of locking the button on a separate function, so it’s easier to reuse. Something like that: $(document).ready(function() { function block(e) { var el = e.currentTarget;…
-
1
votes2
answers109
viewsA: .onscroll is only read once
I think you want to use the document.body and not documentElement. Then I’d be like this: var menuPrincipal = document.getElementById('menuPrincipal'); window.onscroll = function() {…
-
5
votes3
answers1249
viewsA: Why can I create two functions with the same Javascript signature?
Succinct response: This is the "normal" behavior in Javascript. The language has advanced and today it is already possible to use const to declare constants that cannot be superscripted. Elongated…
javascriptanswered Sergio 133,294 -
2
votes1
answer644
viewsA: How do I return the value of a query in the nodejs
The problem here is asymchronism. You have to use callbacks to invoke a function when this value has been returned from the database. If you have the logic that needs it you have to chain things up…
-
3
votes1
answer34
viewsA: How to create a copy of an element, through its property
If you know exactly what the alt you want, you can use it in a CSS selector like this: document.querySelectorAll('[alt="foto"]'); The whole code could be like this: var fotos =…
-
3
votes1
answer2216
viewsA: Python function "repeat ... to <cond. >"
You can use a while thus: contador = 0 while (contador < 9): print ('O contador é:', contador) contador = contador + 1 That way he checks whether the condition contador < 9 is still valid and…
-
3
votes1
answer51
viewsA: Change "on" to "click" in Javascript function
blur that is to say "when the element loses focus". This is what happens when you click outside of this element, and the function runs. Because it "lost focus". The most semantic would be to use the…
-
1
votes1
answer932
viewsA: How to set variable within match method (String)
You can use the constructor new RegExp thus: var res = 'texto'; var regex = new RegExp(res); var str = 'Seu texto aqui!'; if (str.match(regex)) { alert('Palavra encontrada.'); } In simple text cases…
-
2
votes1
answer148
viewsA: How to duplicate visualization of HTML elements
You can do it like this: // procura as imagens todas var imagens = document.querySelectorAll('#A img'); var obj = {}; // percorre as imagens for (var i = 0, l = imagens.length; i < l; i++) { var…
-
1
votes3
answers101
viewsA: What condition can I develop to avoid duplicating values?
Suggestion: Within the while generates a number and checks if it already exists within the array that stores the drawn numbers. If it exists does continue to the while continue, if it does not…
-
3
votes2
answers10552
viewsA: How to take the position X and Y of an element, relative to the screen?
You can use the .getBoundingClientRect() thus: function posicao(e) { var el = this; var coordenadas = el.getBoundingClientRect(); console.log('posição x', coordenadas.left, 'posição y',…
javascriptanswered Sergio 133,294 -
2
votes2
answers863
viewsA: How to add attribute in JSON array?
You have to go through this array and add the numbers (converting these strings to Number) and for example creating an object with the result: var dados = [{ "descricao": "teste", "January":…
-
1
votes2
answers457
viewsA: Count and compare number of keys and values between objects
You can do this recursively, so you can use any type of object without having to configure N loops for that specific object. function compare(objA, objB){ return…
-
2
votes1
answer612
viewsA: Check the amount of elements within a div with an id within a javascript class?
You can use the document.querySelectorAll to select multiple elements with a CSS selector. In your case it could be so: var qtd = document.querySelectorAll('#algo p').length; console.log('A…
-
2
votes1
answer449
viewsA: From a selected checkbox, take the value of an upcoming date attribute
You have to climb the DOM until .input-group-addon, seek out the sibling .input-group-addon and then look for a descendant with data-content. It could be so: $(':checkbox').on('change', function() {…
-
1
votes1
answer43
viewsA: Problem with Eventlistener execution
Change the order of the first two lines, thus the if is run every click. How do you have the if is run once and the addEventListener then always run under the same conditions.…
-
3
votes2
answers587
viewsA: enable input button
Puts the attribute disabled directly in HTML to avoid waiting for Javascript. Then assemble an event osculator to learn when a change occurs in the #cat. It could be so:…
-
2
votes1
answer69
viewsA: Regex to involve console.log expression in eclipse find/replace
You can use [^;]+, searching for "everything" but ;, once or more. Your regex could be like this (example): console[\s\n\.]+log\([^;]*\);…
-
1
votes1
answer244
viewsA: How to wait for Javascript callback
You need to control the flow of these callbacks. A solution would be a pure function (which uses nothing outside itself or its arguments). It could be like this (jsFiddle): function…
-
1
votes3
answers663
viewsA: Method Object.values( ) does not work in internet explorer 9
Object values. is a new Javascript method not yet implemented in all browsers. It therefore did not exist at the time of IE9. But you can use a polyfill like this: if (!Object.values) {…
javascriptanswered Sergio 133,294 -
2
votes1
answer229
viewsA: Javascript onclick/addeventlistener with no anonymous function
You have to create a function that returns another, or you do bind of that argument you need to use. #1 - criaObjeto returns a function function criaObjeto(param){ return function(evento){ // <--…
-
2
votes1
answer29
viewsA: Nodejs module running before the Eventlistener
You have to use the concept of high order Function, that is to return a function to the .addEventListener call, a callback in this case. It could be so: exports.preview = (fileInput, whereToSee)…
-
5
votes1
answer837
viewsA: How to get the indexes of a json with javascript?
var carro = { "modelo": "celta", "ano": 2007 } var chaves = Object.keys(carro); alert(JSON.stringify(chaves)); There is the Object.keys(meuObjeto); that does just that.…
javascriptanswered Sergio 133,294