Posts by Cmte Cardeal • 5,299 points
158 posts
-
1
votes2
answers70
viewsA: How to change style attributes of a . svg?
That would be the way?: .menuimage svg path:hover { fill: black; } .menuimage2 svg path:hover { fill: blue; } <div class="menuimage"> <svg width="79" height="79" viewBox="0 0 79 79"…
-
4
votes0
answers37
viewsQ: What is and what is the exotic Windowproxy object for?
While looking for good links to this answer, I came across a quote from an object called WindowProxy. In the search for explanations, I found this link with the definition: A Windowproxy is an…
-
7
votes1
answer166
viewsA: What is globalThis in Javascript?
Intro The global object is considered a problem that Javascript cannot get rid of due to backward compatibility. Every developer knows the headache of trying to create/modify/remove some Javascript…
-
3
votes1
answer70
viewsA: Vuejs: How do I read a src attribute that is already within a v-html directive?
In the above case, the src thus "../../assets/video/first-video.mp4", because in the end, this is not the path that Vuejs uses to serve the static files. For example, in a project of mine, I have a…
-
3
votes2
answers73
viewsA: How can I get an Array’s Index number?
Using the method reduce, you return an array with the index that has the day equal to 5. We do a check with if (obj.day === 5), we have the code below: let arr = [ {name: "Salário", amount: 150000,…
-
2
votes2
answers52
viewsA: Add element based on array comparison
Assuming you have an array with idof those who have already been assisted, the comparison can be made using only the map and returning the formatted object according to one condition (if the id of…
-
2
votes2
answers114
viewsA: What are "fancy words" (fancy words) in programming languages?
Solved Thanking @Piovezan for their contribution and excellent response, he shared some material to complement it. In this excellent material informed by @Piovezan, is explained some Fancy Words…
language-independentanswered Cmte Cardeal 5,299 -
9
votes2
answers155
viewsA: Is there any way to prevent the use of "new" in a Javascript function?
An alternative is to check the this. You can make a if to check whether the this is an instance of the function itself. Something like: function foo() { if (this instanceof foo) { throw new…
-
6
votes2
answers114
viewsQ: What are "fancy words" (fancy words) in programming languages?
First of all, I don’t know if it’s a concept restricted to languages like Typescript or Javascript, so I assume it’s general purpose. I came across the following codes that I will use as an example…
language-independentasked Cmte Cardeal 5,299 -
3
votes1
answer714
viewsA: Webpack error (Yarn webpack-dev-server-mode Development)
Depending on the version of webpack-cli, has that Issue that explains some changes that have to be made according to the version. Basically for the versions webpack 5.x and webpack-cli 4.x, the…
-
13
votes2
answers455
viewsQ: What is the new Javascript Temporal object?
I recently discovered that you have a proposal on stage 3 a new object to work with dates. This is called Temporal. I analyzed an example code in a post from Linkedin that uses this new API:…
-
3
votes1
answer40
viewsA: My Javascript code loop is not working correctly
Your problem is that you are performing mathematical operations with string. document.getElementById('..').value returns a string, however much the input is of the type "number", and this generates…
-
1
votes1
answer39
viewsA: Change background color and turn on all window lights at night (Javascript only)
Use the ambiente.setAttribute('class', '...'); to change the background color. You can select all elements that have the class yellow, and check if there is any element with this class by making a…
-
4
votes1
answer73
viewsA: Error importing module in Javascript
Assuming that your index js. is being imported in a tag script, I believe the error is that the type specification is missing MIME of the file you are trying to import. In this case, try importing…
javascriptanswered Cmte Cardeal 5,299 -
1
votes3
answers201
viewsA: How to change colors dynamically with Javascript and pure CSS?
Alternative to another answer, which is a good approach in my opinion, you can, after selecting the DOM element, change the CSS property through the .style of that element: function toggle(){…
-
1
votes2
answers368
viewsA: How to take data from a specific field in an XML,with Nodejs,and then save it in the Mongo database
alternative... For those who want to avoid using regex and looking for an alternative solution using some specific library, we can use in Node.JS the fast-xml-parser: Installation: npm install…
-
3
votes1
answer41
viewsA: How to get each item of an XML?
The simplest way, in my view, would be to use a library to do the parse XML for a Javascript/JSON object. Could use the fast-xml-parser on Node.JS: Installation npm install fast-xml-parser Use const…
-
1
votes1
answer31
viewsA: How to customize the track of a slider according to its value
In this case, we can only use Javascript and work on background without changing the CSS file. We can style and change the color only by changing a variable in the Javascript code. We can adjust the…
-
1
votes2
answers196
viewsA: onClick error in Nextjs / React js
This error is due to the factor that Link does not expect to receive a props calling for onClick. We can see it in itself type used by Link: export declare type LinkProps = { href: Url; as?: Url;…
-
2
votes3
answers85
viewsA: RGBA / RGB color syntax in CSS
Complementing the @Ricardopunctual response ... This is a way to simplify the use of rgb or rgba and leave the code in a simpler way. In addition to the rgb, has support for the hsl, color, and some…
-
0
votes2
answers227
viewsA: How to validate the date of birth by Yup
I believe that for the date().max(), we should pass the maximum date with the following format YYYY-MM-DD (year-month-day) for the method max(). In this case we could use the method…
-
3
votes2
answers57
viewsA: How to add Hover to Bootstrap icons
Could do in a way, that would affect all the svg’s of the page, change the property fill every time a hover. Example: svg:hover { fill: rgba(0,0,0,1); /* preenche com a cor "black" */ } <!DOCTYPE…
-
1
votes1
answer44
viewsA: trying to create a single select with array
Let’s create a new select and adjust the attributes name and id as follows: var select = document.createElement('select'); select.setAttribute('name', 'categori'); select.setAttribute('id',…
javascriptanswered Cmte Cardeal 5,299 -
0
votes1
answer26
viewsA: How do I use WHERE using Knexjs as a conditional?
You could do it in a simpler way by passing only the conditional and the parameters to be updated. The data returns array with number of records that have been changed. Can be [1], [2], [3], ...,…
-
5
votes5
answers287
viewsA: How to go through an array of objects, add specific properties and unify those objects where it has a specific property equal to another?
I will share my solution, this being, in my view, a decent alternative to the other answers. Code: const listaProdutos = [ { nome: 'Teclado', preco: 28.0 }, { nome: 'Mouse', preco: 36.0 }, { nome:…
javascriptanswered Cmte Cardeal 5,299 -
1
votes1
answer38
viewsA: Error using split() method
Would not be firstName[0].split(''); instead of firstName.split(''); and lastName[0].split(''); instead of lastName.split('');, for this case? In this way: const pickInitials = function (name) {…
javascriptanswered Cmte Cardeal 5,299 -
0
votes1
answer134
viewsA: Populate() Ngoose only returns Objectid
I think if you’re wrong, you’re in Post.find({}).populate('categories')..., because the correct would be to pass to the method populate the "column", so to speak, that you want popular. You should…
-
1
votes1
answer49
viewsA: Doubt about use of npx together with npm
You should inform the flag --use-npm using the command of npx. Try this way: npx create-react-app nomedoprojeto --use-npm The reason for create-react-app use by default the Yarn is that both were…
-
0
votes4
answers72
viewsA: Get minutes between two times
Why don’t you use asMinutes() directly on d? Just use this method and it returns the difference in minutes previously calculated between, in this case, dtChegada and dtPartida. Take the example: var…
-
0
votes1
answer146
viewsA: Import inline SVG from Absolute path in Next.JS
Whether Eslint is working or not, Eslint keeps saying that the file does not exist or that the type has not been defined I may be wrong, but from what I saw in the documentation, I believe…
-
2
votes1
answer70
viewsA: Error Code: 1136. Column Count doesn’t match value Count at Row 2
I think the mistake is in the third line: ('LIVRARIA FERNANDES', '100110', '2500', '2017-01-22' 'ITAU'), missing a comma before 'ITAU': insert into departamento (NOME, NUMERO, VALOR, VENCIMENTO,…
-
1
votes2
answers299
viewsA: How to save an To-Do-List in localstorage in javascript?
First of all, this code: window.addEventListener('DOMContentLoaded', () =>{ lista.innerHTML = ` <li> ${localStorage.getItem('compras')} </li> ` }) You should iterate on the items from…
javascriptanswered Cmte Cardeal 5,299 -
2
votes2
answers36
viewsA: How to run the same Javascript function for more than one div
Your problem has to do with document.querySelector within the constructor class Slide. It returns only 1 DOM element, then it returns only the first div. You’d have to use the…
-
2
votes2
answers62
viewsA: Find the longest word using . Sort()
The way you wrote it, you can use the rest parameter to put all arguments (where args is an array) of function and do the sort the same way you did: function findLongestWord(...args){ return 'A…
-
0
votes1
answer30
viewsA: Misaligned search bar of the div
Work with the class element pesquisa adding the code: .pesquisa { display: flex; align-items: center; } Using display: flex; and align-items: center; to align input vertically. I put a border: 1px…
-
5
votes3
answers389
viewsA: How to get the date of the first and last days of the current week with Javascript?
I will give a solution that makes use of the library date-fns. The use of this medium reduces the work we would have writing all the logic in hand, as the code becomes more simplified and easy to…
-
0
votes1
answer27
viewsA: How to use Jquery to trigger a function when the page title is changed?
if I can be presented with a valid way of doing this.. Using pure Javascript you can use the MutationObserver which is an API that observes changes in the DOM and triggers a function when it detects…
-
2
votes2
answers258
viewsA: Sort array within another array with Reactjs
I will give an alternative solution to another answer, because she uses the useEffect and don’t know if you intend to use this hook. Basically you can follow 3 steps: Create a function that…
-
1
votes1
answer121
viewsA: How to block translation into an HTML element/tag
You can add, to the tag that contains the text not to be translated, the attribute translate in the tag or if the translation tool is Google Translate, use a class worthwhile notranslate. Just in…
htmlanswered Cmte Cardeal 5,299 -
2
votes1
answer41
viewsA: Check whether multiple HTML elements contain a specific text value
It is always good to separate the functionalities of your code and specific functions. In your case it would be good to create a function that only checks if any id has already been registered and…
-
2
votes2
answers76
viewsA: Delete table row through an ID
Alternative to another answer, you can do it this way, since the id of his <tr> and unique, can associate the same id of his <tr> an attribute that we can call data-id in his…
-
0
votes1
answer124
viewsA: Rounding a value in Typescript
Using simple Javascript/Typescript methods, provided by the class Math, you can round up or down any non-integer number. Behold: function calculoIMC (peso, altura) { return peso / (altura*altura) }…
-
11
votes2
answers469
viewsQ: What are the logical assignment operators ||=, &&= and ??= in Javascript?
I recently came across a code snippet like the one shown below: let alias = req.body.alias; alias = (alias ||= alias = 'generic'); I’ve never seen that operator before ||=, but after a brief search,…
-
5
votes2
answers131
viewsA: Break string into array limiting the amount of times the break is made
A possible solution is you can use regex to find a desired pattern and perform a split only in this first case found pattern. In your case, when the first - is found, perform the split on it, using…
-
1
votes2
answers53
viewsA: ENUM Sequelize Error
This mistake happens because you are calling .init() in class Usuario recursively on Usuario.init(...), then it enters and infinite loop and generates this error. The mistake has nothing to do with…
-
0
votes1
answer26
viewsA: How to display a hidden icon after loading a file through input file
Your problem is here: document.getElementsByTagName('ficha_inscricao_ok').removeAttribute("hidden");, you are using a html tag selector, to catch html elements and there is no tag…
-
1
votes1
answer41
viewsA: Database return in asynchronous function with await
You are using a function of callback at the same time that uses await. There’s no need to do this, since you converted con.query using Promise in function sqlquery, not to mention that this one does…
-
1
votes1
answer31
viewsA: Get html property value via jquery
You can use the api .data(). This Jquery api selects the value of any attribute data-* in this case, a h5. console.log($( "h5" ).data( "pedido" )); console.log($( "h5" ).data( "id" )); <script…
jqueryanswered Cmte Cardeal 5,299 -
1
votes1
answer41
viewsA: How to turn Document.write into column
Just add a <br> in document.write(...) to break the line and display the results in separate lines. See how it looks: var multiplicador = prompt("Qual tabuada você quer?") var limite =…
-
1
votes1
answer490
viewsA: Error when setting values a loop "React Limits the number of renders to Prevent an Infinite loop"
The fact that you enter an infinite loop is due to the fact that you call the setDataClimate in the loop for within the body of the function, you shouldn’t do this!. The React documentation itself…