Posts by BrTkCa • 11,094 points
375 posts
-
4
votes2
answers728
viewsA: How to separate numbers from three to three, backwards, in Javascript, without regular expression?
In "nail", I created this function that converts the number into String to be able to traverse the elements, and then use the substring to go cutting and riding every three. var n1 = 1000; // 1.000…
-
1
votes1
answer439
viewsA: Onclick respect required field
In that case the onclick will be executed anyway. For this lock validation to be activated only if the criteria are met, put in the event onsubmit and take from the onclick. It could be something…
-
1
votes1
answer75
viewsA: changing the css of the pseudo classes of elements with jquery is possible?
You cannot manipulate because technically psudoclasses is not a part of the DOM, so it is inaccessible by javascript. There are other ways to do this, several of them listed here, i particularly…
-
1
votes1
answer1513
viewsA: How to identify the child element clicked through the event click on the parent element
You can use the target: $('.tipo-cadastro').click((e) => { console.log(e.target); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div…
-
1
votes1
answer707
viewsA: Pass variable Angularjs through JS function
You can call a Function and take the value using angular.element: HTML onclick="exibirModal()" JS function exibirModal(){ var nome = angular.element('#idMeuController').scope().dado.nomeFunc;…
-
0
votes2
answers428
viewsA: Jquery - No rounding number
One option would be to force the number of decimals with toFixed: var num = (933 / 9).toFixed(20); // 103.66666666666667140362…
-
6
votes2
answers382
viewsA: Which means [] in angular.module
The second parameter is the list of dependencies of the module being created. Translated into Portuguese from documentation: Modules can list other modules as their dependencies. Depending on a…
-
2
votes1
answer851
viewsA: How to pick up a specific piece of information within a Json with Node.JS?
You can use Array#Map to map only the first item of each array: var obj = { "pair": "BTCBRL", "bids": [ [2257.89, 0.20752212, 90852987], [2257.88, 1.01201126, 90800395], [2249.98, 0.05052466,…
-
2
votes2
answers771
viewsA: How to remove a grid column using jquery
One way you can hide all the columns in the rows is to iterate through them. I made an example so that you can have logic as a basis and be able to adapt to your scenario:…
-
2
votes3
answers2419
viewsA: How can I calculate elements in Javascript
I changed a few things in the code you made available. I didn’t understand the use of reduce and a mask function that does not exist. But to perform this calculation, you can simply get the values…
-
5
votes4
answers3526
viewsA: How to pick a String that is between Javascript tags using Regex
Using the Javascript regex API: var text = "Meu nome <[email protected]>"; var regex = /(<)(.*)(>)/; console.log(regex.exec(text)[2]); Explaining // limits the area to run a regex (<)…
-
2
votes2
answers220
viewsA: Problem with access to "Undefined" properties
You can check if it exists before trying to access it: files = $(".X"); if (files[0]){ if (files[0].files.length >= 1) { //... } } if (files[0]) will return true if it does not fall under any of…
-
1
votes3
answers1024
viewsA: Take comma-separated values from the database and organize them into <li>
With Javascript, it is possible to separate the text by comma, and add the li: var texto = 'Site em HTML5, Alta velocidade, Responsivo'.split(','); texto.forEach(function(item) { var li =…
-
3
votes4
answers3595
viewsA: How to put picture in input type reset?
You can let the value blank not to go text on input and place a background image by css. background-size: cover indicates that it is for the image to obtain the total space of the element. Example:…
-
2
votes3
answers528
viewsA: How to compare indexes of two objects and return what is different?
Another way is to convert the object into string and save to an array. In this case, even if the size of the objects is uncertain, in case the first is larger than the second, it will work. var arr…
-
1
votes1
answer120
viewsA: Redeem values from a modal item to update it in the database
After the table is loaded, you can include a class in the buttons edit to "listen" to the event click. So to get line values, you use two levels up using Parent, and search for the description of…
-
5
votes3
answers84
viewsA: Partial selection of a class with jQuery
If I understand what you’re trying to do, you can use regex to remove the class that starts with p and have numbers later, something like that: $("div[class^='chart-']").removeClass(function(index,…
-
2
votes2
answers172
viewsA: Capture Document click to close menu that is open
You can check if the target is your button and ignore the next action: $(document).click(function(event) { if ($(event.target).attr('class').indexOf('classe_botoes') > -1) return; // verifica se…
-
1
votes1
answer73
viewsA: JQUERY programming logic
You can put inside a loop by searching how many elements start with the id Content: function selectStep(n) { // obtem a qtd de elementos na tela que começa com Content var size =…
-
2
votes1
answer99
viewsA: How to add input dynamically after second table header
You can target the second header by placing a specific class: HTML <tr class="segundoHeader"> ... </tr> Javascript $(".adicionarCampo").click(function () { novoCampo =…
-
3
votes2
answers1115
viewsA: How to do javascript PROCV (excel) function
Starting from the principle that this is the structure of your table, the idea here is: Scroll through all cells in the table Since each row will have two columns, increment by two (and access the…
-
5
votes2
answers70
viewsA: Javascript for each record in my view
The problem is that you are using the selector id and it cannot repeat itself. Switch to any other selector, such as data-toggle="tooltip" for example. <script type="text/javascript">…
-
1
votes3
answers4343
viewsA: How to download file without back-end
If you want to leave it separate in a function: function download(uri, nome) { var link = document.createElement("a"); link.download = nome; link.href = uri; link.click(); }…
-
0
votes3
answers1438
viewsA: How to get value from selected checkbox
var els = document.querySelectorAll("input[type='checkbox'"); var selecionados = ''; for (var i = 0; i < els.length; i++) { if (els[i].checked)…
-
0
votes2
answers1393
viewsA: Return something in the query when there are no records
When you receive the data from the server, you can normalize the output in javascript. An example would be something like: $.ajax({ url: '', method: 'GET' }).success(function(data){ // caso o…
-
2
votes2
answers89
viewsA: When uploading, the file name becomes the title
Javascript-enabled: <html> <head> </head> <body> <input id="arquivo" type="file" > <script> document.getElementById("arquivo").onchange = function(){ var name =…
-
1
votes2
answers14983
viewsA: Handle error: "Uncaught Typeerror: Cannot read Property of 'value' Undefined"
You can check if the property exists, in negative create one with a default value: success: function(data){ // verifica se é undefined if (!data[0]){ data = [{rede: ''}]; // seta vazio para a…
-
2
votes1
answer415
viewsA: Click on multiple lines
The attribute id should be unique in the form, should never be repeated. You will have to get through another selector, such as a class or an attribute any:…
-
-1
votes2
answers93
viewsA: Random background images with Angularjs
It is possible with angular element., delegating an embedded Angular subset of jQuery, called jQuery lite or jqLite.…
-
1
votes2
answers743
viewsA: Extract arrays and objects from JSON returned with jQuery
Using dataType as json you can get the return in this format to iterate the keys or values. jQuery.ajax({ type: "GET", url:…
-
3
votes1
answer1807
viewsA: Text field mask does not work in mobile environment
One option is to use a mask in pure javascript. Using regex might be something like: document.getElementById('telefone').addEventListener('input', function (e) { var aux =…
-
3
votes2
answers10617
viewsA: How to change image when clicking?
You can leave each style in different classes, and then change the class as you click, using the property classname javascript. In this example, I left as a "toggle", because the user can select and…
-
3
votes3
answers313
viewsA: Dynamically generated ajax tags are not viewed by jquery
You can use the method .on, successor of .delegate, since the element was added to the DOM after it was initially mounted and interpreted by the script. Try something like: $(document).on('click',…
-
3
votes2
answers256
viewsA: How to print only the first 5 characters?
A string is a javascript character array, so you can get a character range from that array using Slice. Example: var tds = document.getElementsByTagName("td"); for (i = 0 ; i < tds.length ; i++){…
-
3
votes6
answers29816
viewsA: How to create space before or at the end of the text contained between html tags?
And   to insert a tab space. div{float:left;} <div>Texto 1</div><div> texto que quero um espaço antes</div>…
-
3
votes3
answers228
viewsA: What is the default value for the "resize" attribute in a textarea?
According to the MDN: Gecko 2.0 introduced support for resizable textareas. This is Controlled by the resize CSS Property. Resizing of textareas is enabled by default... Translating gets: Gecko 2.0…
-
2
votes1
answer188
viewsA: Add header in Jquery’s getJson function
$.getJSON is a simplified: $.ajax({ dataType: "json", url: url, data: data, success: success }); Therefore, to set a header, a call like: $.ajax({ dataType: "json", beforeSend: function(request) {…
-
12
votes4
answers31300
viewsA: How to disable resize from textarea?
textarea { resize: none; } <textarea></textarea>…
-
1
votes2
answers382
viewsA: Extract values from a javascript string
You can use Location.search who will return from ? to the end of the URL. Then process the result. Example for your case: var url = window.location.search; // retorno será algo como:…
-
0
votes1
answer112
viewsA: Refresh by clicking on the tab (Foundation)
You can use the function load jQuery, targeting the same page and the div. Probably will match with ajax where will bring the new content. HTML <div class="tabs-panel" id="panel2"> Conteudo2…
-
0
votes1
answer732
viewsA: Comparing Attributes of a List with Javascript
The idea here is: Store all values of lis in an array Check if the first attribute of the first item is equal to the second The criterion is that the attributes are in the same position, otherwise…
javascriptanswered BrTkCa 11,094 -
6
votes5
answers4393
viewsA: Transforming a JSON information into a variable
Utilize . to access the object’s key value: var obj = { "pair": "BTCBRL", "last": 2280.0, "high": 2306.0, "low": 2205.0, "vol": 113.17267938, "vol_brl": 255658.20705113, "buy": 2263.0, "sell":…
-
3
votes2
answers548
viewsA: Navbar scrollbar does not appear on another width
Usually to "force" the scroll bar is used overflow on target. Example: body { overflow-x: scroll; // somente para horizontal overflow-y: scroll; // somente para vertical overflow: scroll; //…
-
4
votes1
answer15751
viewsA: Check if radio button is selected
The right thing to do is to use prop: $("elem").prop("checked"); Instead of: $("#opcao2").cheked() $("#calculo").click(function() { if ($("#opcao2").prop("checked")) {…
-
1
votes3
answers106
viewsA: Limit dynamic fields in jquery
Place a counter, and if you reach the limit does not add more: var contador = 0; var limite = 5; $(function() { var scntDiv = $('#dynamicDiv'); $(document).on('click', '#addInput', function() { if…
-
6
votes2
answers9324
viewsA: Subtract days from an input date with javascript
var data = new Date(); document.write('Hoje é: ' + data.toLocaleString()); data.setDate(data.getDate() - 14); document.write('<br>14 dias atrás: ' + data.toLocaleString()); In your case:…
-
4
votes2
answers514
viewsA: Take value from within a function
The http Angularjs is asynchronous, so the variable will be undefined at this time. One option is to use it in success, something like this: $http.get(base_url + 'main/lastId/')…
-
2
votes4
answers4863
viewsA: How to pick the first word of a string with jquery?
A hint if the text starts with spaces is to use the method Trim before separating the string. var str = ' Primeira palavra da string'; var primeira = str.trim().split(' ')[0]; console.log(primeira);…
-
2
votes4
answers257
viewsA: Grab link on date and play on src from img on Hover
It is possible to obtain the events mouseover and mouseout and change the attribute src using attr, something like: var src = 'images/manada.jpg'; $( "img" ).mouseover(function() {…
-
3
votes4
answers3163
viewsA: Removing spaces in input fields
It is possible to use the event paste. Then separate by spaces and then join without them: function removerEspacos(e) { var clipboardData, pastedData; e.stopPropagation(); e.preventDefault();…