Posts by Sergio • 133,294 points
2,786 posts
-
5
votes2
answers7451
viewsA: .Empty() in javascript, how to do?
The .empty() in which case it is simply innerHTML = '';. This native Javascript script could be like this: var input = document.getElementById('input'); var image_holder =…
-
4
votes3
answers164
viewsA: Retrieve a checkbox id by the class using getElementsByClassName()?
You can use the selector :checked which gives you all selected checkboxes. The code could go like this: function selecionaDactes() { var selecionadas = document.querySelectorAll('table :checked');…
javascriptanswered Sergio 133,294 -
3
votes1
answer175
viewsA: How to put cursor:move on a div draggable with javascript?
No API to change the cursor of an element that is in drag with HTML5. Perhaps this will be possible with the future version CSS4 with pseudo selectors for drag... If you want to control the cursor…
-
3
votes1
answer30
viewsA: Tip on how to write my code better
Things to be improved: $($(this).find('#algo')).text() This can be summarized to $(this).find('#algo').text() send many fields in ajax See you get all these lines: var piiCodUsuario =…
-
0
votes1
answer100
viewsA: How to solve this problem
If you’re using jQuery, use .change() to trigger the event. The error in question comes from this line: var elementS = '123'; and it turns out you’re overwriting the value of the variable, not the…
-
0
votes1
answer1208
viewsA: Json return error {"isFulfilled":false,"isRejected":false} + Node
Looking at your code I see that event.findAll() generates a Promise. So it would be enough to have return event.findAll() without the .then() and then use like this: app.get('/api/events',…
-
1
votes1
answer1932
viewsA: How to add an object in an array within another object
Don’t use the eval for this case, he is dangerous. The localStorage is useful but not to trust, and use strings of localStorage in Val is bad practice. You can do it like this, note how I use it []…
-
2
votes1
answer53
viewsA: Array within an object, how is the correct syntax?
You’re using wrong syntax, with [] inside {}, what you want is the other way around, since arrayDebits is an array with objects inside: [{obj1}, {obj2}, etc...] that would look like this: {…
javascriptanswered Sergio 133,294 -
2
votes2
answers180
viewsA: Ajax request in ES6 constructor
You got two problems here: #1: The this inside ajax is pointing to jQuery instance, not your constructor because it is not a property of it. #2: Ajax is asynchronous, you can’t do console.log after…
-
2
votes1
answer51
viewsA: How is a PHP page updated/included via AJAX?
PHP script and Ajax are not related. You can think of Ajax as a browser "visit", which calls a PHP file and returns the answer it gives you, as if you were a user. So PHP errors that you have are…
-
1
votes1
answer50
viewsA: Doubt with DATAPICKER
To API of .datepicker() has the method for this, beforeShowDay that accepts a function that calls for each date. This function has to return an array with the following index (only the first is…
-
1
votes1
answer231
viewsA: Uses Tree line by line
Puts the ID in the table, not in ul(s)): <table id="tree1"> <tr> <td> <ul> <li><a href="#">Empresa</a> even because duplicate Ids is wrong HTML syntax.…
-
0
votes1
answer77
viewsA: Return results in different inputs
Echo a JSON with json_encode, so you receive a json object in Javascript. Will you have more than one result? but you also have LIMIT 1 in the query and do directly echo of fetch without the while.…
-
10
votes1
answer269
viewsA: CSS - Selector "::"
That’s called pseudo-elements and are available in most browsers. CSS selectors usually refer to DOM elements, this pseudo selector :: refers to elements that are not different in the DOM. It may be…
-
2
votes1
answer220
viewsA: Create parameters in div to use in Javascript
For this practice are fields data-. Much like what you did, but it would be <div class="teste" data-abacaxi="false"></div> In HTML that is called attributes data-* and there is an API to…
-
1
votes1
answer255
viewsA: Automatic calculation of averages using JAVASCRIPT or PHP
Suggestion: var linhas = [].slice.call(document.querySelectorAll('tr')); linhas.forEach(function(linha) { var inputs = [].slice.call(linha.querySelectorAll('input')); var mediaFinal = inputs.pop();…
-
1
votes1
answer396
viewsA: Jquery function to show and hide text?
The best thing would be to have a class and the CSS do the hide/show part. Class could be like this: .esconder .mostrar { display: none; } And a working example would be like this: function…
-
1
votes1
answer95
viewsA: How to know the result number inside a loop with mysqli_fetch_array?
You can use an external counter to know which is the first passage of the loop: $i = 0; while($aux = mysqli_fetch_array($sql)){ $id = $aux['id']; if($i == 0){ echo "<span…
-
1
votes1
answer619
viewsA: Random matrix filling with javascript
If I understand correctly you want to generate a Matrix 10 x 12 with 0s and 1s. You can do it like this: function gerarMatriz(x, y) { /* ou se preferires mais estático tira os argumentos e faz: var…
-
0
votes3
answers843
viewsA: How to extract a specific text from a string via Javascript
You can use a Regexp to extract these question/answer pairs. It could be something like this: var texto = "p: perguntaA r: respostaA p: perguntaB r: respostaB p: perguntaC r: respostaC"; var regex =…
-
1
votes2
answers367
viewsA: Run javascript counting click to show option on screen?
You can do it with less code, more optimized: $(document).ready(function() { var QtdClick = 0; // iniciando var inputs = ['extraum', 'extradois', 'extratres', 'extraquatro'].map(function(id) {…
-
2
votes1
answer75
viewsA: Select filter stopped working
You’ve got the dials mixed in half. You are using ID on the selector, but select has no ID, it has name. Should be $('select[name="list_citys"]'). Besides $(".list-citys").find("ul") doesn’t make…
-
2
votes1
answer369
viewsA: How to create a regex to remove lines with #?
Suggestion: <?php $foo = " #01 = linha comentada; 02 = valor para ser interpretado; #03 = outra linha comentada; "; $limpa = preg_replace('/[\s\t]*#\d+[^;]+;/im', '', $foo); echo $limpa; ?>…
-
10
votes2
answers213
viewsA: How to remove img tags from text?
You can use a temporary element to clean that. I usually do like this: function limparHTML(html) { const proxy = document.createElement('div'); proxy.innerHTML = html; return proxy.innerText; }…
javascriptanswered Sergio 133,294 -
3
votes2
answers3003
views -
32
votes2
answers7627
viewsA: What is the difference between Javascript and jQuery?
jQuery is Javascript. jQuery is a written/built library with the Javascript language. There are two main reasons to have a library like jQuery: be able to simplify life for the programmer, with…
-
2
votes2
answers190
viewsA: Why doesn’t :Hover work this way?
You have a class .thumb-box plus, along with .episodio-data {, who is ruining everything. At times: .player-info .episodios-lista .lista-episodios .thumb-box:hover .thumb-box.episodio-data { must…
-
1
votes2
answers59
viewsA: Code problem
If I understand correctly, every time the code goes into aleatorio loses an attempt. Then the tentativa2-- must be immediately at the entrance of that function, before the if which checks how many…
-
7
votes2
answers357
viewsA: Eventos Bubbles Javascript
Summary: bubbles is a property of some events and indicates whether the event can be captured outside the element where it was created, or not. Lengthy explanation: For example when we click on a…
-
3
votes1
answer673
viewsA: Delete item from an Inioc 2 array
splice accepts the start index in the first argument and the number of elements to remove in the second argument. In your case it should be .splice(index, 1), which in practice is: delItem(item){…
-
9
votes1
answer84
viewsA: $ and $$ are now native browser functions?
These are console-only methods, shortcuts to facilitate the programmer. This is confirmed in chrome documentation here and in the Edge documentation here where it says: $() is a shortcut to…
-
1
votes1
answer32
viewsA: Export function using third party package
Note that your file/module is exporting a function and not an instance of woocommerceAPI. When you have module.exports = () => {...} this exports () => {...}, what you want to have is…
-
0
votes2
answers100
viewsA: How do I combine a checkbox with a switch?
You have to put an argument on switch It can’t just be empty. You have to have switch (uma_variável){ and then if it is x do something, if y do something, etc... That said I think the switch is not…
-
4
votes3
answers71
viewsA: Difference between Immediate Child and First-Child?
Look at the example: div>p { font-family: Garamond; color: brown; text-decoration: underline; } p:first-child { font-family: cursive; color: blue; } <div> <p>Primeiro</p>…
-
2
votes2
answers2719
viewsA: Add and remove Jquery class
If you have several elements and you want to remove the class to all that were not clicked (and have toggle of the class on clicked) you can do so: var filtros = $j('.filters__filter.tamanho');…
-
2
votes2
answers603
viewsA: enable and disable Ubmit according to input field validity
You’re duplicating code unnecessarily. Some suggestions: This must be in HTML and not in Javascript: $('#btnCadastrarEmp').prop('disabled', true); This way ensures that there is no FOUC effect, or…
-
5
votes1
answer29
viewsA: Is it okay to include a little bootstrap on the page you’re missing?
No problem, that’s quite usual. What you have to consider is: pages without scripts is always preferable from the page loading speed and weight perspective scripted pages are often more useful…
-
6
votes1
answer296
viewsA: How to select the name and salary of the employee of 'MG' who receives the highest salary?
SELECT nome, salario FROM empregados WHERE alocacao="mg" ORDER BY salario DESC LIMIT 1 Split: nome, salario, the columns you want to appear in the result FROM empregados, the table name WHERE…
-
1
votes2
answers799
viewsA: Can I return 2 value in an Ajax?
You have several options, one is to add the ID to the ..serialize(), another is to send an object with two keys. The .serialize() generates a _stringde chaves e valores, tipo _querystring_ onde as…
-
2
votes1
answer83
viewsA: Reallocate elements in the DOM
You can use the .insertBefore() the syntax is: elementoPai.insertBefore(novoElemento, elmentoReferência); Example: var ul = document.querySelector('ul'); var primeiro = document.querySelector('ul…
javascriptanswered Sergio 133,294 -
0
votes1
answer90
viewsA: I can’t do a javascript screen search
Passes an array to the method .listarTodos, that in case she is not defenida he uses all same: this.listarTodos = function(veiculos) { var dados = ''; if (!veiculos) veiculos = this.veiculos; if…
-
1
votes1
answer40
viewsA: I can’t get him to print everything together as a vector, it’s all separate
At times dados += '<td>'+this.veiculos[i]+'</td>'; you need a <td> for each element of that array this.veiculos[i], and you can do it like this: dados +=…
-
3
votes1
answer91
viewsA: Convert path (String) to object
Use a split to "break" this string and then a loop that creates an object. It could be like this: var string = "/home/username/Documentos/app.txt"; var props = string.split('/').filter(Boolean); //…
-
4
votes2
answers1062
viewsA: What does the data-reactid attribute mean?
That one data-reactid is an attribute data- HTML used by React to interact with the DOM. React creates a virtual DOM, a collection of arrays and objects that it manipulates internally to avoid…
-
3
votes2
answers1174
viewsA: How to disable an already enabled Function, or vice versa?
You have to get the function itself to remove that ondblclick. Suggestion: pass the this as an argument ondblclick="zoomInside(this)" and then in function: function zoomInside(el) {…
javascriptanswered Sergio 133,294 -
2
votes2
answers2765
viewsA: How to start closed Accordion
Withdraws the class in of HTML. Seeing the documentation of course the class in is used to open the section: .collapse hides the content .collapsing applied during the open/closed transition…
-
6
votes2
answers54
viewsA: Running a script through the name attribute does not work
Your dial is looking for a input, should be looking for a select. In addition, two comments: if you have several select, gives them the same class and uses $(".form-control").on(, so all will be…
-
0
votes4
answers768
viewsA: Add mask from a select
Create an object to map the masks. And then you can use it like this: var mascaras = { user_cpf: '999.999.999-99', // aqui podes ter mais campos } $('#select').on('change', function() { var mask =…
-
1
votes2
answers283
viewsA: Array ordering based on the order of another array
If you only want two equal arrays you can do: arrayA = arrayB; or even arrayA = arrayB.slice(); but this does not prevent elements of the array from being referenced from one array to the other,…
-
3
votes2
answers204
viewsA: check jquery email as if it were two strings
I usually use a regex like this [^@]+@[^@]+\.[^@]+. The idea is: [^@]+ N characters other than @ once @ again N characters other than @ one time point (there may be more within [^@]+, but here…