Posts by Sergio • 133,294 points
2,786 posts
-
103
votes9
answers13997
viewsA: How to create a website without reloading every click on a link?
In a conceptual way, there are three options: #1 - Single file without AJAX In this case you can have all the content on the same page. The content that is not to show must be hidden with, for…
-
7
votes5
answers1876
viewsA: Retrieve a final value from a json in Javascript
A variant without jQuery, infused here: var url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=-12.9945,-38.5266&sensor=false'; httpGet(url); function httpGet(theUrl) { xmlhttp = new…
-
12
votes2
answers579
viewsA: Why does setting a CSS property with the ! attribute not work in the . css() method?
Yes it does! Only with a variant: .css("cssText", "color: green !important;") Example To add more properties just add in the same string: .css("cssText", "color: green !important; font-size:50px;")…
-
5
votes1
answer252
viewsA: How to use fadein() with an append()?
Test like this: var count = 5; $('#addCount').click(function () { var p = $('<p>' + count + '</p>'); // criar o elemento p.hide(); // escondê-lo $('#new_elem').append(p); // "appendê-lo"…
-
5
votes3
answers8971
viewsA: Go to the next element with next and add a class to the previous one
Here’s another alternative, using only the class hidden as you suggested: $('.next, .prev').on('click', function (event) { event.preventDefault(); trocar($(this).hasClass('next')); // chama a função…
-
11
votes5
answers10769
viewsA: How to mark and unmark a row from a table by clicking on it?
You can use it like this: To apply across the board can use $('table tr'); var tr = $('table tr:not(:first-child)'); // o :not(:first-child) é util no meu exemplo somente porque usa th…
-
1
votes3
answers997
viewsA: How do I add jQuery library with Javascript?
The problem is that your script loads asynchronous, and because of this jQuery is called directly after colocaScript() and that is before the script have carried. Use like this: window.onload =…
-
19
votes2
answers6588
viewsA: How can I pause and play a gif?
+1 by an interesting question. That(s) functions you put work well. It is not actually possible to stop a . gif which is by nature animated. The other solutions I know are: replace gif with a static…
-
1
votes3
answers3834
viewsA: Google Maps coordinates via a Widget on a website
You can extract the coordinates from the center of the map on your page by calling the function .getCenter() of the Google Maps API. So the user can drag and center the map where he wants and then…
-
2
votes4
answers1855
viewsA: PHP/Codeigniter error "Array to string Conversion"
Use the Count() or sizeof() to get arrays size. In your code you can cache the value of the $branch array size out of the loop to avoid calling the Count() function every iteration. Test like this:…
-
1
votes2
answers93
viewsA: Refresh a window when I close another
There is a lot of detail missing from your question. I will respond in a relaxed way with the hope that it will help you. My suggestion: HTML <div id="conteudoJanela"> <div>Adicione um…
-
5
votes2
answers447
viewsA: jQuery who changes div background specifies
The accordion itself already assigns a class to the element that is open, so you can use .ui-state-active to reach the open div. Note that the plugin uses a background-image that you need to disable…
-
16
votes2
answers24059
viewsA: View div in Hover
If you are going to make this HTML it is best to use only CSS. Create a div for each link and its contents. Example: <div class="item"> <a href="">Ver mais</a> <div…
-
2
votes1
answer506
viewsA: jQuery validation plugin + tabs
Ids have to be unique! You should use classes if you group with the same name. Having the same ID for various elements is "invalid HTML" and can cause only the first to be considered, and other…
-
1
votes3
answers3165
viewsA: Function to increment value within the div
I re-organized your code. The initial value must be outside the setInterval not to be re-written. Test like this: var valorInicial = 0; function aumenta(id) { var elemento =…
javascriptanswered Sergio 133,294 -
4
votes3
answers3981
viewsA: Problem with Hover in CSS
To use a selector :hover in the element <td> he must be glued to the class .info_table. So you can use, no spaces: .info_table:hover{ Example…
-
6
votes3
answers1322
viewsA: Get the value of the "option" that was clicked either to select/deselect
Try to use it like this: $('#multiselect').multiselect(); $("#multiselect").on("multiselectclick", function (event, ui) { console.log(ui.value); }); Example I found this in the documentation:…
-
48
votes6
answers42802
viewsA: What is the difference between . on("click", Function() {}) and . click(Function() {})?
The great advantage of the method .on() is to allow delegation in cases where the 'selector' is added dynamically (after the code has been run). In other words: the .on() serves for elements…
-
18
votes2
answers275
viewsA: Performance of string substitution
You can use the jsperf.com, there it is possible to assemble tests to test different variations. Fez a test and gave me 13~15% slower with Regexp. The code I used: var texto = 'amarelo verde…
javascriptanswered Sergio 133,294 -
1
votes1
answer1726
viewsA: How to save the results of a "drag-and-drop" in table?
jQuery’s embedding allows two parameters in the drop function, the second is the dragged element, so you can try: function drop(ev, ui) { var dropped = ui.draggable; var texto = dropped.innerText;…
-
6
votes3
answers2188
viewsA: Use symbol in input text, and disappear when typed
You can use a background-image which changes position (disappears) in the focus: input { background-image: url(http://www.levenmetwater.nl/static/global/images/icon-search.png); input:focus {…
-
2
votes1
answer149
viewsA: String handling with str_replace
Example with ER’s: $entrada = "/Olá¡ hoje é domingo/"; $saida = preg_replace('/(\/)(.*)(\/)/',"<span class='comentario'>$2<span>",$entrada); If you want to "pick up the contents from //…
-
8
votes5
answers10236
viewsA: echo or print, what really is the best option?
Are virtually identical. The print has the detail of returning a value, 1 in case it has run. So it can be used $printou = print('foo'); The echo allows concatenating variables/strings: echo 'Olá!',…
-
42
votes7
answers78990
viewsA: How does this if/Else work with "?" and ":"?
What you have is a ternary conditional operator, a variant of if/Else, very common not only in Javascript. The syntax is: [ condition to be tested ] ? [ answer if true ] : [ answer if not true ]…
-
5
votes3
answers1400
viewsA: What are the ways to apply Eval in Javascript
In fact setTimeout and setInterval can use a method similar to eval() if they do not receive a function (anonymous or referenced) as the first parameter. The desired, good practice, would be: //…
-
3
votes3
answers1421
viewsA: How to call a function in javascript through a text box?
You can use the val(). Try it like this: var input = document.querySelector('input[type=text]'); input.addEventListener('blur', function(){ eval(this.value); }); But I strongly recommend read this…
javascriptanswered Sergio 133,294 -
1
votes2
answers282
viewsA: foreach PHP for Javascript
The best here is to create an object array. So you can do: var markers = []; markers.push = {id : 'marker_1', lat : 59.441193, lon : 24.729494); // etc And then use a numeric for loop. Example: var…
-
76
votes6
answers20131
viewsQ: Difference between single and double quotes in PHP
What is the difference between single and double quotes in PHP? Yesterday I was working with a string from a google json I used explode('\n', .. to separate a string. When I used the explode in "Mon…
-
2
votes2
answers2633
viewsA: Input type date, how to format output
Different browsers show the date in different ways. Chrome for example uses your country/location format to format the date. However, apart from this visual difference, the date that is sent is the…
-
1
votes2
answers732
viewsA: How to select one or more items in the jQuery UI Multiselect plugin?
To select several options you only need to set the "Selected="true". With jQuery you can use: .prop('selected', true); or false to remove. And to know the value: $("#multiSelect").val() Example…
-
1
votes2
answers4360
viewsA: How to fix column in table accessible?
Here is a suggestion: var posicoes = $('tr > th:first-of-type, tr > td:first-of-type').map(function () { return $(this).position() }); var largura = $('tr > td:first').outerWidth();…
-
13
votes8
answers4914
viewsA: Do not allow saving image of a web page
It is not possible to block user content. In fact when the page opens the image is already cached on the computer. I am (personally) against changing the expected functionality of a browser/page.…
-
7
votes3
answers1357
viewsA: Retrieve date and local time of an arbitrary day in an arbitrary Timezone, considering daylight saving time
This function does not exist native in javascript, it has to be done "by hand" or by using a library. So here’s one I made now (between last night and today): First, state all time zones on a JSON:…
-
1
votes4
answers1759
viewsA: How do I make all items in a menu equal in size regardless of quantity?
To achieve this you have to give display: table; at the ul and display:table-cell; at the li. Test like this: .top-menu ul { width: 100%; display: table; } .top-menu ul li { display:table-cell;…
-
15
votes6
answers8117
viewsA: How to remove a "href" from a <a> tag with Jquery/Javascript?
The modern solution to disable a link is CSS only: (for modern browsers) $('#minhaID').css("pointer-events", "none"); // e para re-activar basta usar: $('#minhaID').css("pointer-events", ""); Demo…
-
8
votes3
answers48813
viewsA: Receive external JSON data from PHP
The second parameter of json_decode() is to force the output of the Decode to the structure of an associative array. Your code is correct if you don’t have it true in the json_decode. If you have…
-
34
votes5
answers76380
viewsA: How to pin a "horizontal menu" to the top of the window when scrolling the page?
You need to control when your menu reaches the top of the window and at that time change the menu position to fixed. Thus $('#meuMenu').offset().top will give you the distance to the top. When the…
-
3
votes4
answers11708
viewsA: How do I call a function by pressing Enter in <input>
Click on Enter within an input submits/submits to form, while in the textarea creates a new line. So the answer to your question goes through what I mentioned above and also through code that…
-
1
votes2
answers546
viewsA: How to Fade Only Item Clicked
It seems to me that one of the problems here is that you fade/Out to all elements with a specific class, the best is to refer it by this. So I could use:…
-
5
votes2
answers549
viewsQ: Import events in Google JSON format
I want to import events from a non-public server-side Google Calendar (PHP) in JSON format. Since I only want to receive information and do not need to edit/create events I assume there is a way…
-
5
votes5
answers1657
viewsA: How to add class to the next element when clicking the button?
You can use it like this: $('button#anterior').click(function () { $('.minhaClasse').removeClass('minhaClasse').prev().addClass('minhaClasse'); if (!$('.minhaClasse').length) {…
javascriptanswered Sergio 133,294 -
5
votes8
answers48548
viewsA: How to pass parameters in function calls by reference in Javascript?
What you can use here is the jQuery.proxy(): $('div').on('click', $.proxy( minhaFuncao, this, 'minha variavel1', 'minha variavel2' )); function minhaFuncao(a, b) { console.log(a, b); } Example So…
-
3
votes10
answers29077
viewsA: Scroll through an Array and check if any element is empty
In associative arrays it is best to use one foreach since the keys of your array are not numeric where a cycle for can be used as you have in your question: So an example: if…
-
1
votes3
answers526
viewsA: Tag script is not printed with jQuery
The best solution here is to create a new element script with pure javascript and make append to the element you want. var script = document.createElement( "script" ); script.type =…
-
6
votes2
answers42348
viewsQ: How to update/sync my repository master on github with the original master
Using the command line, how can I update/sync my master with the original master from where I did the fork. What are the different ways and their options, what is best, and how history is…
-
5
votes1
answer162
viewsQ: How to use github live code for development, testing and demos?
How can I use Github code in real time in a demo or in development? When I try to use code in jsFiddle or jsBin I get the error: Refused to execute script from…
-
7
votes1
answer162
viewsA: How to use github live code for development, testing and demos?
The solution is to use a Github service that provides files with the header content type correct. So the url provided is almost the same, just need to remove the . (dot) Before…
-
4
votes1
answer2385
viewsA: Load content dynamically with AJAX
I think your problem is the "Scope"/scope of the this within the $.ajax that is in the wrong context, pointing to the ajax function and not to the element that triggered the event. Try it like this:…
-
61
votes4
answers141141
viewsA: How to redirect the user to another Javascript/jQuery page?
In this case jQuery is not necessary. The solution goes through simple javascript. Here are two options: Option 1: window.location.href = "http://answall.com"; // ou uma variante com o mesmo efeito…
-
7
votes6
answers636
viewsA: How do you turn the average to red?
I would add a CSS class that would be introduced in php. For example: for($i=0;$i<count($aluno);$i++){ $media = $aluno[$i]["media"]; $notaVermelha = ''; if($media < 20){$notaVermelha =…