Posts by Sergio • 133,294 points
2,786 posts
-
13
votes7
answers57425
viewsA: Check/Deselect Checkbox from a button
The problem is that in if you should test the this, and not a collection of elements: function marcardesmarcar() { $('.marcar').each(function () { if (this.checked) this.checked = false; else…
-
6
votes2
answers210
viewsA: I’m having a hard time understanding the logic
The logic is: create a function called fontes which receives as input any sentence Here is a minimalist example of function function fontes(frase){ alert(frase); // só para verificar }; write this…
javascriptanswered Sergio 133,294 -
1
votes1
answer173
viewsA: jScrollPane with jQuery Sortable from 2 lists
I did some tests on your page and the only solution I see (and tested) is to add a div extra with both <fieldset class="linhaIndicador"> within it. This new div will have overflow: hidden; and…
-
6
votes1
answer1648
views -
5
votes1
answer59
viewsA: Preview information when selecting field in input
Yes it is possible. If the information is on the server side you will need to ajax and in the select you will need to listen to the event change. Ajax is a tool/method for communicating between the…
-
8
votes3
answers1922
viewsA: What is the appropriate amount of changes to a commit?
The simple answer is: You choose. The complete answer would be: it depends on the versioning system you want to use. The most commonly used system is the Semver that uses 3 parameters separated by…
-
4
votes3
answers3942
viewsA: Scroll on page adds "ACTIVE" class to menu
Here is a suggestion: Explanation: creates a function addClass to assign the class to the li from the right menu cache the li's of the menu and the positions of each section, as well as each element…
-
3
votes1
answer211
viewsA: jQuery Datapicker error page with Ajax
The problem is that when you run AJAX, the elements that had a calendar disappear and are replaced by new ones. Even if the content is the same, removing and re-writing elements of the DOM causes…
-
0
votes2
answers897
viewsA: Open specific accordion by clicking on a list
You can use this code on each page once they have the well-defined hash/url and equal to anchor: var hash = window.location.hash; // ir buscar a string no url, por exemplo #para-sua-empresa var…
-
1
votes1
answer67
viewsA: "append" event on page load
Must do so: jQuery(function ($) { $('#DIV2').append($('#DIV1')); }); In the code I had, this was a pointer to the clicked element, ie $('#DIV1'). And when the click appeared the div2 received by…
-
5
votes4
answers1634
viewsA: Scroll with Jquery
You need to have in the menu some target indication for scroll. Could be the id of the widget stored in a property data, a href/anchor or other. If using an anchor (<a>) may need to use the…
-
20
votes1
answer41918
viewsA: Traverse string and replace a specific PHP character
You can use the str_replace(), the parameters of this function are: str_replace(search, substitute, source, $occurrences) seek out - the text to search for substitute - the text that should replace…
-
4
votes4
answers6348
viewsA: Detecting Line Break
Line breaking can have different formats. The best way to "catch" it is to be comprehensive in regex. Suggestion: string.match(/(\r\n|\n|\r)/gm); The selector \n is the essential. Worth reading this…
-
1
votes1
answer54
viewsA: How do I get the top number that my animation is at the moment?
The method .animate() has a function Progress that can be called for this you want: $(function () { $(".cair").animate({ top: "+=385px", }, { duration: 6000, "complete": function () {…
-
2
votes2
answers163
viewsA: on() and bind() are not working
The main problem here is that the this inside the ajax function is not the same as the this out of the function. The scope is different... This has easy solution, which is to create an intermediate…
-
4
votes1
answer132
viewsA: IF-ELSE problems
You have two problems with your code. The first problem is that when you want to compare two variables you have to use the ==, or ===. What you use is an assignment =, and this does not compare…
javascriptanswered Sergio 133,294 -
25
votes3
answers11309
viewsA: How to delete duplicate spaces in a string?
You can use a regular expression for this: var str = "00000.00000 111111111.111111111111 33333333" str = str.replace(/\s{2,}/g, ' '); Dividing the Regex and replace in parts: \s - any white space…
-
2
votes1
answer412
viewsA: Drag & Drop Jquery UI how to hide Div after drop?
The drop has an event dropthat triggers a jQuery function, this function has two parameters, one of them the object ui that contains the element that was "dropped". So inside this function you only…
-
6
votes2
answers6247
viewsA: Remove comma with jQuery
Example: http://jsfiddle.net/DCeU6/ Option A You can use a regular expression to take out only the last comma. I also added another replace to clear whitespace. var string = $('.tags').text();…
-
39
votes7
answers46159
viewsA: Remove repeated elements within a Javascript array
You can use it like this: var arr = ['foo', 'bar', 'foo']; var novaArr = arr.filter(function(este, i) { return arr.indexOf(este) === i; }); console.log(novaArr); //dá ['foo', 'bar'] In short version…
javascriptanswered Sergio 133,294 -
7
votes1
answer2736
viewsA: Shoot animation with scroll
I got tired of looking in your plugin. I couldn’t find any relationship between ScrollMagic and the TweenMax who placed... So here is a solution without the plugin. Worth what it’s worth...…
-
11
votes3
answers666
viewsA: Function with variable amount of parameters, what better way to do?
You can use . call() or . aplly or even call the function in the most convectional way, and within the function, use the reserved word arguments function foo() { console.log(this, arguments); }…
javascriptanswered Sergio 133,294 -
6
votes1
answer233
viewsA: How to calculate the dimensions of an SVG element
The most consistent solution seems to be .getComputedStyle. And since IE8 does not support svg elements, neither the .getComputedStyle so in the case of IE8 and earlier "Unsolved problem is`. So, as…
-
2
votes2
answers376
viewsA: jQuery Toggle Animation is not working
The .click() jQuery does not support more than one function as parameter. The .hover() is that you have that option for the "Hover-out". What you can do is create a flad/flag:…
-
13
votes1
answer233
viewsQ: How to calculate the dimensions of an SVG element
How to calculate the dimensions of an element svg consistently across browsers? In fact the only one not to respond consistently is Firefox. It would be interesting to understand the reason for the…
-
4
votes2
answers80
viewsA: Css in all php/mysql generated Ivs
To add CSS to dynamically generated elements have two options: #1 - give this element a class and add the rules of that class to your CSS So in PHP you add the newElement class while ($row =…
-
2
votes4
answers2040
viewsA: Problem with height of Ivs that do not accompany each other’s content
I believe the solution here lies in display: table / table-row / table-cell like the @Philip referred. However, to complete the answers and because jQuery is in the tags, here is a hint with jQuery.…
-
2
votes2
answers672
viewsA: Event fires second only, after sequence of user actions
When you click on button it also fires an event focus (http://jsfiddle.net/Xqfnu/). One option, similar to the idea of @mgibsonbr would be to fire a blur at the moment of clicking. This solves the…
-
6
votes3
answers1882
viewsA: How to use Fixed position within a div?
When I give position: fixed then the element behaves as a free and independent element of the position of its relative. If you want to prevent this "free" behavior with jQuery, you can do so but I…
-
1
votes3
answers1135
viewsA: Bootstrap navbar dropdown focus control menu after click
Daniel, here’s a suggestion: http://jsfiddle.net/Lqdxf/ $('.navbar-collapse').keyup(fazerScroll); function fazerScroll(event) { if (!$('.navbar-collapse').is(':visible')) return; var navBar =…
-
2
votes1
answer3322
viewsA: Center vertically icone (img) followed by text in a row
What you need to adjust is the vertical-align of the image. Try using this in your CSS: img { vertical-align: text-bottom; } Example without specifying vertical-align: http://jsfiddle.net/KZxab/1/…
-
7
votes2
answers807
viewsA: Do not view PDF inside the browser
The common answer to this is that you should change the link to instead of being a file to use a server-side page (PHP for example) and set up http header to force the download. But in HTML5 there…
-
3
votes1
answer344
viewsA: Show options to customize budget
Use if (this.checked) { instead of if ($(".minhaClasse").attr("checked")){ I could also use the .prop("checked"), which is the current/substitute solution for .attr() since version 1.6. Changing…
-
5
votes1
answer248
viewsA: jQuery Unique, difference in Chrome and Firefox?
The .unique()jQuery was not designed for numbers or strings. jQuery documentation reads: Sorts an array of DOM Elements, in place, with the Duplicates Removed. Note that this only Works on arrays of…
-
3
votes1
answer1505
viewsA: html buttons dropdown menu
The problem is when the mouse goes over the element with class .Galeria. Download the z-index to force the mouse to view the menu. I tried this and it worked well: http://jsfiddle.net/cgPtw/1/…
-
2
votes2
answers1196
viewsA: How to make an Animate up to the mouse position and after starting to follow the mouse?
Rodrigo, here is my suggestion: Example: http://jsfiddle.net/853qb/ $(document).ready(function () { var marcador = $('.MarcadorMenu'); var LeftInicial = marcador.css('left'); var WidthInicial =…
-
9
votes1
answer480
viewsA: How to mix two colors using Javascript?
I think what you’re looking for is an average of each color. Take a look here: http://jsfiddle.net/XdQ88/1/ function tratarInput(arr, degraus) { arr = arr.toLowerCase(); if (arr.length == 3) { var…
-
6
votes1
answer2104
viewsA: Real-time values in the input type="range" class
Take a look at this example: http://jsfiddle.net/LuKBm/ In practice you don’t need jQuery and you have two options. Listen to the event input that changes with each step the mouse moves, or listen…
-
1
votes1
answer90
viewsA: jQuery Mobile: page Events
One thing you should always keep in mind is to have everything you can have in CSS in CSS. For example, if you want to hide an element until the page loads, then it’s best to hide it directly in the…
-
18
votes6
answers7191
viewsA: How to put default (default) arguments in a Javascript function?
In javascript that current browsers (2015) use would have to have a if somehow within the function. But in the future, with browsers that support the new ES6 standard it is already possible. What is…
-
1
votes2
answers266
viewsA: Updating Header with Jquery after page reload
If there is a way to add the class via Ruby on Rails this seems to me the "cleaner" route, and then I have no knowledge. However, you can use the url to make jQuery assign a class to li that has a…
-
2
votes1
answer276
viewsA: Add and Remove percentage proportionally
Test like this: var items = { item1: 10, item2: 40, item3: 50 }; function distribuir(el, qtd) { var somaTotal = 0, nrItems = 0; for (var este in items) { if (items[el] != items[este]) { somaTotal +=…
-
1
votes1
answer155
viewsA: Tabs with slideup() and slideDown() for left and right
Here is an example of horizontal slide. I must say that slideup() and slideDown() do not allow to do the same horizontal effect. This is an example I made, the resemblance to your code is to use the…
-
2
votes5
answers5718
viewsA: Popup with AJAX and jQuery
If you already have a function Aprovar() then to run this function every click, then you can tie an event like this: $('button').on('click', Aprovar); Depending on what type of message you want to…
-
1
votes4
answers143
viewsA: Get date-img value
Take a look here at us methods of this plugin. What he’s missing is: var novaImagen = '<img src="' + imagetooltip + '" />' $(this).tooltipster('content', novaImagen)…
-
4
votes2
answers1390
viewsA: Dynamically change a class background
If you have the CSS inside the HTML you can do so: var style = $('style').text(); var newStyle = '.color {color: red; }'; $('style').text(newStyle); Example The selector $('style') go find the…
-
11
votes2
answers10853
viewsA: Calling the Javascript function of the parent file from within an iframe
Note: There is a protection called CORS that prevents opening content from a site within iframe if the server does not allow it. There’s another rule called "same-origin policy" which prevents a…
-
2
votes3
answers1664
viewsA: How to create a plugin for jQuery’s $() function
A syntax to create a new plugin that is in the documentation so jQuery is: $.fn.esverdear = function() { this.css( "color", "green" ); }; $("a").esverdear(); // Muda a cor de todos os elementos para…
-
13
votes3
answers26625
viewsA: Simple comparison between dates
I believe it is enough to create date objects and compare them. function checarDatas() { var form_insere = document.form_insere; var data_1 = new Date(form_insere.datainicial.value); var data_2 =…
javascriptanswered Sergio 133,294 -
2
votes1
answer1182
viewsA: Show a div for each dropdown option
It would be practical to have in your HTML a class for all Divs/cities. So it would be much easier to select all these Divs <div id="Joinville - sc" class="divcidade"> To use simple javascript…