Posts by BrTkCa • 11,094 points
375 posts
- 
		1 votes1 answer32 viewsA: Use parameter passed in function within map()When passing a variable to select a property in an object, use obj[variavel]. Considering the following object: obj = { nome: 'Lucas', idade: 24 } If we use the following function: function a(key =… javascriptanswered BrTkCa 11,094
- 
		0 votes2 answers705 viewsA: How do I find the '[' character in a Javascript string?Can use indexOf which will return to the position of first occurrence: "Package sem arquivo [ 11/7/2017 10:16:32 AM ]".indexOf("["); // 20 To know of all occurrences: let str = "Package sem arquivo… javascriptanswered BrTkCa 11,094
- 
		0 votes2 answers6045 viewsA: Delay JavascriptYou can use the setInterval: function repeticao() { for (var i = 0; i <= 5; i++) { (function loop(i) { setTimeout(function() { console.log(i); }, 2000*i) })(i); } } repeticao();… javascriptanswered BrTkCa 11,094
- 
		1 votes4 answers1375 viewsA: Count options from a selectTo simply know how many elements there are inside another you can try to retrieve them, something like this: let options = $("select option"); // options.length irá indicar qtd de elementos Example… 
- 
		2 votes4 answers943 viewsA: Adjust one td css onlyYou can use the pseudo-selector first-child that will apply to all the first: tr td:first-child { width: 50px; text-decoration: underline } <table border="2"> <tbody> <tr>… 
- 
		2 votes3 answers1610 viewsA: Concatenate single quotes into date variable?You can resume the date string with toISOString: let dt = new Date(); console.log(typeof dt.toISOString(), dt.toISOString());… 
- 
		1 votes1 answer1157 viewsA: How do I ask permission from the user, to get his location? showing an Alert with the options allow or not allow.It is possible by Geolocation API of the browsers, such that is accessible in the object navigator.geolocation. Example of the MDN: HTML <p><button onclick="geoFindMe()">Exibir minha… 
- 
		1 votes2 answers293 viewsA: Set object key by a variableJSON forms a powerful data structure from which you can take better advantage. My suggestion is you change to a array of objects to represent the scenario. Instead of: [ { A: [idx1, idx2], B: [idx1,… javascriptanswered BrTkCa 11,094
- 
		2 votes2 answers421 viewsA: Regular Expression to capture after last barAnother way: const str = "file:///home/pasta/pasta/img/intro-bg.jpg"; const basename = str.replace(/^.*\//g, ''); console.log(basename);… 
- 
		0 votes3 answers130 viewsA: Deselect checkbox in chainYour conditions are wrong, it could be something like: $("#ck1").change(function(){ // pega o evento de mudanca if( $(this).is(':checked') ) // verifica se checkbox 1 esta marcado $("#ck2").show();… 
- 
		3 votes3 answers306 views
- 
		2 votes3 answers7670 viewsA: Check if element exists inside another element with JavascriptIn querySelector it is possible to use CSS selectors, so it is possible to use Child - pai > filho. const elem = document.querySelector("#pai > #filho"); if (elem) { console.log("Elemento… javascriptanswered BrTkCa 11,094
- 
		1 votes1 answer623 viewsA: Validate select with jQuery ValidatorYou only have a small error in your script, the correct is multiSelect and not multiselect. $(function() { $('#unidadeNegocio').multiSelect(); }); $('#form').validate({ rules: { "unidadeNegocio[]":… 
- 
		1 votes2 answers524 viewsA: How can we not lose Session from one tab to another?For this you can use the localStorage, where it can be shared between browser tabs.… javascriptanswered BrTkCa 11,094
- 
		7 votes3 answers6016 viewsA: Convert JSON to EXCELThere are some solutions on the international site with pure Javascript. I use (and recommend) the library alasql. Example var jsonArray = [{ idcancelamento: "383", idcliente: "2409",… 
- 
		4 votes2 answers109 viewsA: Best way to get text + HTML from an arrayTo insert a text with HTML markup into an element you can use $(this).html(res); instead of $(this).text(res); $().text() treats content as a string while $().html() treats the string as HTML.… 
- 
		0 votes2 answers178 viewsA: Complete fieldsYou can change the event blur for keyup: $("input[name='descri']").keyup(function(){}) 
- 
		2 votes1 answer51 viewsA: use of regex on a switchThe problem is that you may be trying to use match in a number, the correct would be: var regex = /[1-7]/; if( !regex.test(day) ){ day = 8; } Example function dayOfWeek(day){ var regex = /([1-7])/;… 
- 
		6 votes1 answer294 viewsA: CSS recognizing Javascript variables within html, is it possible?You can change the value of the element property by javascript: let elem = documento.getElementById("duvida2"); function posicaoMouse(ev){ ev.preventDefault(); var x = ev.clientX; var y =… 
- 
		3 votes2 answers175 viewsA: Validate all inputs in SUBMITTo validate text and email in Submit you can combine the type plus required HTML5 that it will not allow submission if the data is invalid. Example <form> <input type="email"… 
- 
		1 votes1 answer50 viewsA: Webpack Optimization of MinificationDoes it make any difference in terms of performance he catch the . js or .minjs.? Yeah, it makes a lot of difference. The minified file, as its name says, is smaller, and this generates performance… 
- 
		1 votes2 answers45 viewsA: How to add the value of the id attribute and the text of a select from the click of a button event?You can slightly change the structure that stores the ids and textos and add that way: $("#tableHtml tbody").find('input[type="checkbox"]').each(function() { if ($(this).is(":checked")) { var _id =… 
- 
		8 votes2 answers2509 viewsA: What is the function of Function in jQuery and what is the right way or time to use?To be honest, they’re very similar. When you use: $(function() { }); is a shorthand for: $( document ).ready(funcao); which experienced programmers use. When using: $j(function() { }); is actually… 
- 
		3 votes2 answers1008 viewsA: How to scroll in Javascript?You can check if the scroll was to the desired element. Function credits isScrolledIntoView comes of that answer. var wasExecuted = false; function move() { var elem =… 
- 
		1 votes1 answer168 viewsA: Select component with an Angular requestThere are some ways to do what you want, the first is to invoke the click on change, thus: document.getElementsByClassName('selectpicker')[0].addEventListener('change', handleEvent); function… 
- 
		5 votes1 answer702 viewsA: Construct an Array with the date rangeThe idea here is to add the days to the date using data.setDate. As long as the initial date is less than the final, it will be added and included in the array. The two extra functions are to keep… 
- 
		0 votes1 answer78 viewsA: Doubt sum day in Date JavascriptThe problem is the date format. This new Date(document.getElementById("<%= txtDataInicio.ClientID %>").value); will return you null if the format is in "10/16/2017", you will need to format… javascriptanswered BrTkCa 11,094
- 
		1 votes1 answer965 views
- 
		0 votes2 answers510 viewsA: How to load html page with the scroll bar of a DIV at the end?Only with HTML can you point the anchor that the page will go to where it is, something like that: http://localhost/index#message Or with javascript when the page is loaded: function irAté(div){ var… 
- 
		4 votes3 answers266 viewsA: Send what is being typed from one input to another in real timeYou can use regex to swap special characters or spaces for nothing. let input = document.getElementById('um') let input2 = document.getElementById('dois') input.onkeyup = function(){ let valor =… 
- 
		0 votes1 answer101 viewsA: How to maintain a "checked" checkbox after filteringI suggest you create a property in your items, which could be: <div ng-repeat="post in posts | filter:{components:component} | filter:{classification:class}:true"> <ul> <div… 
- 
		2 votes2 answers461 viewsA: What is the Riot.js?Clearly stated in the documentation, Riot was inspired by Facebook’s React. Their proposal is to have simple syntax, and to be light - lightness is an audacious point to touch, because if the… 
- 
		1 votes2 answers7149 viewsA: Simulate Click in JavascriptYou can call the function directly as well: function evento(string){ console.log(string); } <input type="button" id="meuElemento" onclick="evento('Teste')">… javascriptanswered BrTkCa 11,094
- 
		1 votes2 answers611 viewsA: Remove blank select option AngularjsYou need to set an initial value for your model, this way: $scope.modelcompraevenda.subClasse = $scope.modelcompraevenda.listSubClasse[0]; 
- 
		2 votes2 answers916 viewsA: Orderby with ng-repeat nested in the AngularjsYou will need to create another view template due to being nested array. In the case of the plane, since the order is semantic, you will need to use a weight for each plane. Concatenating the… 
- 
		1 votes1 answer50 viewsA: Exit confirmation messagegetElementsByName returns an array, so you need to check the index: function confirmExit(){ if( ( !document.getElementsByName("interessado")[0].value )|| (… javascriptanswered BrTkCa 11,094
- 
		1 votes1 answer367 viewsA: How to check whether or not there is a rel=""You can try to get the element using jQuery, if it is different from null it is because the element exists. Example //para executar apos o DOM ser carregado $(document).ready(function(){ let prev =… 
- 
		0 votes1 answer44 viewsA: Select Checkbox valueYou can get the element by using the function click jQuery: $("[type='checkbox']").click(function() { // verifica se está selecionado if($(this).is(':checked')){ console.log($(this).val()) } });… 
- 
		1 votes3 answers6672 viewsA: Validate file extensionYou can use a regex to validate whether the file contains a certain extension. Example let validos = /(\.jpg|\.png|\.gif|\.pdf|\.txt|\.doc|\.docx)$/i; $("#arquivo").change(function() { let fileInput… 
- 
		1 votes1 answer67 viewsA: Session library for Nodejs/Hapijs?Passportjs is a good option for login and it is available for Hapi. With express check if the user is logged in to intercept with express-Session. I do not have property to talk about Hapi, but… 
- 
		0 votes1 answer827 viewsA: How to view files before downloading?Open your link in a new tab: let link = document.createElement('a') link.target = '_blank' let url = window.URL.createObjectURL(blob); link.href = url.replace(/([\w]{8})-([\w]{4}-){3}([\w]{12})/g,… 
- 
		1 votes1 answer524 viewsA: Synchronous function to check files in Nodejs?Can be sent when the event ends: pdfMake = printer.createPdfKitDocument(docDefinition); let stream = pdfMake.pipe(fs.createWriteStream('../pdfs/Tabela.pdf')); pdfMake.end(); stream.on('finish',… 
- 
		0 votes3 answers110 viewsA: Javascript - How to make the date attribute of a li belong to another liYou will need to know in advance who belongs to whom in order to relate. Example: let marcas = [{ marca: ' ford', modelo: 'Edge' }, { marca: ' ford', modelo: 'Fusion' }, { marca: ' fiat', modelo:… javascriptanswered BrTkCa 11,094
- 
		2 votes4 answers3827 viewsA: Percentage MaskYou can use the Translate: $('.numero').mask('Z99,99%', { translation: { 'Z': { pattern: /[\-\+]/, optional: true } } }); <script… 
- 
		1 votes1 answer123 viewsA: Is product image in <option> of <select> possible?Within the option only text is allowed. MDN documentation: Permitted Content: Text, possibly with escaped characters (such as é). With jQuery an option is the selectMenu.… 
- 
		-1 votes1 answer94 viewsA: Data javascript formatConfusion happens only when using alert, if we trade for console.log everything is right. The difference is that the alert flame toString to print the contents of some object, more or less like… 
- 
		13 votes1 answer744 viewsA: What is the difference between save and Insert in Mongodb?Insert will always create a new document while the save update an existing document, or insert a new one. If you only run save without parentheses on the Mouse console db.teste.save, the code of the… 
- 
		2 votes1 answer224 viewsA: How to adapt a JSON to create a table in pdfMake?Taking advantage of the structure of your another question, if I understood the format could do so: function preencherPDF(conteudo) { let corpo = [ ['Id Usuário', 'Id Post', 'Título', 'Texto'] ];… 
- 
		1 votes1 answer383 viewsA: How to use data from a query in mongoDB?You can fill in the contents of the PDF by invoking a function for this in the callback successful consultation, thus: db.open(function(err, mongoclient) { mongoclient.collection('postagens',… 
- 
		4 votes4 answers211 viewsA: Like a tag on a table element with jQuery?The idea here is: Use ES6 features as Operator spread and Arrow Function to return an array Use the Array#map to return only the contents of tds Apply the regular expression /[0-9.]/g to capture…