Posts by Sergio • 133,294 points
2,786 posts
-
0
votes2
answers1042
viewsA: Breaking line array jQuery
Three alternatives: as you have and putting together white-space: pre-wrap; in the CSS using <br> as separator and .html() in time of .text() using <p></p> #1 var nomes = ['Joao',…
-
1
votes2
answers209
viewsA: When triggering an event in an array element (with querySelectAll) trigger only one element of another array (also with querySelectAll)
I think you’re complicating it. First of all, it can be done only with CSS, like this: * { font-family: sans-serif; margin: 0 auto; box-shadow: border-box; position: relative; } body { left: 0;…
-
2
votes2
answers1128
viewsA: Do not allow Retroactive date in the Date type field
You can do it like this: var input = document.getElementById('ultimoDiaTrab'); input.addEventListener('change', function() { var agora = new Date(); var escolhida = new Date(this.value); if…
-
2
votes3
answers484
viewsA: Disable DATE Input After selecting Select option
Notice that <div class="col-sm-4" id="ultimoDiaTrab"> has the same ID as your input <input type="date" id="ultimoDiaTrab" name="ultimoDiaTrab" class="form-control" /> Iso is invalid HTML…
-
2
votes2
answers7151
viewsA: Uncaught Typeerror: Cannot read Property 'split' of Undefined
3 things to fix: function createMark(i) { // <--------------- mudança 1 var imagePath = "marker" + (i + 1) + ".png"; var image = imagePath; var markers = []; if (!locations[i]) return null; //…
javascriptanswered Sergio 133,294 -
29
votes3
answers9049
viewsA: What is a Transpilation?
Transpilar is a mix of compile and translate. In other words it is a tool to generate a new version of a given code. In the last years in Javascript the language has advanced a lot. As browsers move…
-
1
votes1
answer1603
viewsA: How to make when the button is pressed it continues with different color
You can do this with Javascript or with HTML and CSS, but with some ingenuity... If you do it with HTML you have to change the structure a little bit and it could be like this, but it’s like "hack".…
-
3
votes2
answers1768
viewsA: Single quotes are allowed in JSON?
To specification of the JSON format clearly states that only double quotes can be used, more specifically U+0022.…
-
1
votes1
answer53
viewsA: Use fadeOut('slow') in Ajax Array that contains several id
My suggestion is, you might have a string of ids like this: foo,bar,baz have this in an array and treat everything as an array/collection... Thus: $('#btn_delete').click(function() { if…
-
4
votes1
answer2563
viewsA: Use single or double quotes for strings in Javascript?
It’s a matter of taste. They make no difference in Javascript. There may be cases where one is more practical, for example: var stringA = 'Olá Mc\'Neil'; var stringB = "Olá Mc'Neil";…
javascriptanswered Sergio 133,294 -
1
votes1
answer1686
viewsA: Uncaught Syntaxerror: Unexpected token Nodejs
You’re responding to file requests .css and .js with the content of index.html, so you’re getting character errors < within CSS and JS. You have to read the request.url to know what was requested…
-
2
votes1
answer27
viewsA: Preprocessor Stylus - Error running Stylus watch
Use the flag -o specifies that the file (after space) is the destination of the CSS that will be compiled. Thus: stylus -w main.styl -o main.css
-
1
votes1
answer33
viewsA: Jquery Event Click does not work in image preview
$(".file-preview").on('click', "img[class='kv-preview-data file-preview-image']", function() { alert('addMore click event'); }); You have to delegate that event since that image doesn’t exist when…
-
2
votes1
answer13558
viewsA: Project error: Uncaught Syntaxerror: Unexpected token var
Removes all the var of the arguments of the functions, this is wrong syntax in Javascript. That is to say: changes function getLogStr(var lineNum) { for function getLogStr(lineNum) {. These…
-
2
votes1
answer51
viewsA: I am unable to display the array data
Three things come to mind: What’s the idea of myFunction(url);? that line makes no sense because myFunction is what you want to use to process the right ajax result? missing the code that calls ajax…
-
3
votes2
answers43
viewsA: Problem with '.data()' and its value within an if
Two problems: the .data() already gives you a String, you do not need (nor should you) use .val() comparison should be made with == or ===, use only = is an assignment. Solution:…
-
9
votes1
answer139
viewsA: What is the correct use of the "in" javascript operator?
'innerHeight' in window As you are looking for a property you should use a String, otherwise it’s like you’re searching for the contents of the variable innerHeight in window, or whatever you have…
javascriptanswered Sergio 133,294 -
4
votes2
answers985
viewsA: How to allow a regular expression of letters and numbers to accept cedilla
/[^a-zA-ZçÇ 0-9]+/g Working with regex in accented letters is +/- difficult in Javascript. In other languages there is the class \p{L} which includes all characters that are letters. In Javascript…
-
2
votes1
answer115
viewsA: How do I share a property with other components in React?
To pass values to descendants you must use props. To pass all the props of a parent element to a descendant you can use {...this.props} in the props of the discriminating element. Example: class Pai…
-
3
votes1
answer143
viewsA: check empty input
Give me the idea that you’re using Mootools... that’s the case? Anyway, with this API you can do it like this: var qttDeclared = tr.getElement("input[name$='[qttDeclared]']").get("value").trim();…
-
5
votes3
answers638
viewsA: How to take the current time and decrease 24 hours of it?
You can use the .setDate and spend a day less than the current date, so it will change the internal date of that variable to what you want: var data = new Date(); data.setDate(data.getDate() - 1);…
javascriptanswered Sergio 133,294 -
6
votes1
answer113
viewsA: Javascript + Canvas
This is because when the browser reads the head and run the script, the document.body does not yet exist. That is document.getElementById('myCanvas'); can only run after the browser has read this…
javascriptanswered Sergio 133,294 -
3
votes1
answer70
viewsA: Please help me finish this Javascript script
You don’t have to (or should) do it so long. Because it’s easy to introduce mistakes and because it’s a lot of work :) Use the initial value and remove the value of the notes you distribute. So you…
javascriptanswered Sergio 133,294 -
3
votes4
answers2314
viewsA: How do I insert the value of a variable into an HTML attribute using pure Javascript
To put the id of the query string within an attribute data- you can do it like this: function qsGet(chave) { var qs = location.query.slice(1); var pares = qs.split('&'); for (var i = 0; i <…
-
3
votes1
answer3822
viewsA: How to Collapse and Expand a text using HTML5 only?
I don’t see how this can be done without Javascript. The closest is to using the :active but that only works the moment the mouse is pressed: .collapse { height: 0px; overflow: hidden; transition:…
-
1
votes3
answers906
viewsA: Format date on page load
I may be late with my answer...: If you want to do it in the browser and all dates are in format yyyy-mm-dd you can do it like this: $('input.form-control').each(function(){ this.value =…
-
1
votes1
answer118
viewsA: Function parameters not previously defined
Having optional parameters is common in several native methods, what is "strange here" is the organization callback itself being optional. This is documented, and if it is not passed this callback…
-
2
votes1
answer520
viewsA: Display image according to time by repeating javascript function
To show the image you want when the page loads you can also do it on the server. If you want the page to change the image while it’s open then you need Javascript. Note: you should tag…
-
6
votes2
answers4034
viewsA: dynamic url in ajax
You can use the location.search to get the querystring of the URL (), e depois usar caminhos relativos, sem. Would look like this: jQuery.ajax({ url: "/jogoteocratico/consulta.php" +…
-
4
votes1
answer133
viewsA: Regular Expression REGEX HELP
Suggestion: const regex = /<[^\/]*span[^>]*>[^<]+</g; const subRegex = />([^<]+)</; const string = `{ < span class="filteredAds"> de teste< /span>, < span…
-
4
votes3
answers1216
viewsA: Count elements and display a quantity
You can do this with Javascript and a CSS selector like this: document.querySelector('.conteudo p').style.display = 'block'; .conteudo p { display: none; } <div class="conteudo">…
-
0
votes2
answers135
viewsA: Return all constructor parameters of a function in Javascript
To know what properties an intuition has you can do like this: var Pessoa = function(data) { this.nome = arguments[0].nome || ''; this.telefone = arguments[0].telefone || ''; // ... n parâmetros ...…
-
13
votes1
answer1535
viewsA: What is the difference between parseint() and Number()?
They have different purposes, but can be used for common purposes. The Number does type conversion, to Number. He will try to turn a string of digits into a number: Number('0123'); // 123…
javascriptanswered Sergio 133,294 -
2
votes3
answers664
viewsA: How to convert a numeric value to Boolean?
test the guy of that variable first. If string will always give true. Checks with: console.log(typeof status, status); To be sure use Number(status), or status == '1' ? true : false.…
-
1
votes3
answers528
viewsA: How to compare indexes of two objects and return what is different?
You need to know which Object has the most keys, and then iterate until you find a key the other doesn’t have. You can do it like this: function comparar(a, b) { var axb = Object.keys(a).length >…
-
1
votes2
answers28
viewsA: AJAX and Weakmaps requests
The question here is basically the same as this, or this. That is: ajax is asynchronous. That means that: // pseudo código: var x = 10; ajax(function(){ x = 20; }); console.log(x); // dá 10 What…
-
2
votes2
answers622
viewsA: Canvas delete correct text
Forehead like this: ctx.clearRect(x, y, canvas.width, -parseInt(txt_size, 10)); The problem here is to know the height of the text inside the canvas and That’s not very easy. As you are using pixels…
-
3
votes4
answers8175
viewsA: What is the opposite of the "None display"?
Depends on what the initial value. According to MDN the initial value if nothing has been applied to the element is inline. But this does not apply to all elements. There is a interesting article…
-
3
votes1
answer167
viewsA: Use if() inside . catch() - error: Unexpected token if
The arrow function syntax (Arrow Function) is wrong. You can do this (assuming that this function returns a Promise): minhaFn('foo').catch(error => { if(error){ console.log(error); // Outro…
-
5
votes2
answers85
viewsA: Function Optimization (probably with for loop)
This code can be much reduced... there’s a lot of repetition there. Hint (with slight HTML modifications -> see example below): var slides =…
-
1
votes2
answers1635
viewsA: Search all columns of a table
I’m going to search only the first one td you can do in the tr with all its contents. Replaces td.innerHTML.toUpperCase().indexOf(filter) > -1 for tr.textContent.toUpperCase().indexOf(filter)…
-
6
votes2
answers234
viewsA: Reference loss in function call
This is a common problem, which can be solved with Arrow functions or with .bind(). Abridged: a) Why this reference loss occurred? When we run a function such as callback of a Promise the execution…
-
5
votes2
answers753
viewsA: What is the difference between 301 and 302 redirects?
When the desired page is not in the expected location you can use 301 (for a permanent change) and 302 (for a temporary change). Login redirects or fruit of page navigation are something else, there…
-
0
votes1
answer756
viewsA: React.js Error trying to access nested Json data via component state
You have to take into account that both fetch() and the this.setState({ dados: json }); are asynchronous. This means that the first time React tries to render that component the value of…
-
0
votes1
answer33
viewsA: jQuery counting automating ID’s
You have to delegate that event and tell jQuery what to look for. To delegate the event you need to use an element that already exists, father of these Divs that are being inserted. For jQuery to…
-
0
votes1
answer1042
viewsA: Function js is executed several times
When you have it in HTML <table id="jogo_1" onclick="getTableClick(this, event);" this will make the function run when there is a click on the element table or one of their descendants. Example:…
-
3
votes4
answers4863
viewsA: How to pick the first word of a string with jquery?
You can do that by breaking the phrase into pieces and using .shift(). var strg = 'Primeira palavra da string'; var word_one = strg.split(' ').shift(); console.log(word_one); Or via regular…
-
4
votes1
answer2971
viewsA: Click on the link that leads to another part of the same page
To do this with native Javascript you have to consider a few things I explain below. If you want/can do this with jQuery you can see this other answer. Making Javascript Simple and HTML Steps Are:…
-
8
votes3
answers230
viewsA: Reduce code repetition with loop creation (loop)
You can do so with Javascript: for (var i = 0; i < 14; i++){ document.getElementById("baixo_final[" + i + "]").className = "baixo_final_2"; // ou somente `"baixo_final" + i + ""` caso não…
-
1
votes1
answer1007
viewsA: How to use the content of a javascript variable in another js file?
You need to create a way to communicate between files. O require is requested once per module and stays in memory. If you pass a function then you have the door open to go searching, or pushing new…