Posts by bfavaretto • 64,705 points
902 posts
-
2
votes2
answers469
viewsA: jQuery onload x jQuery onDomready
This thing you’re saying is a little confusing: if you need to load JS files in a certain order, but at some point one of these files refers to another that has not yet been loaded, while via…
-
25
votes2
answers36925
viewsA: Change the "placeholder" color without affecting the "value" color
You need to use non-standard CSS properties to only affect the placeholder: ::-webkit-input-placeholder { color: red; } :-moz-placeholder { /* Firefox 18- */ color: red; } ::-moz-placeholder { /*…
-
7
votes4
answers1082
viewsA: How to verify that the properties of the window object are native?
I don’t know how much this would be compatible with all browsers, but if you convert the function to string, you’ll see the source code in the case of non-native functions, and a string containing…
-
18
votes3
answers3756
viewsA: Problem using subst in text with PHP
Your string is probably encoded as UTF-8, which is desirable, as you can represent an immense amount of special characters. In UTF-8, certain characters, including all accents, occupy more than one…
-
3
votes1
answer202
viewsA: How to bypass an HTTP redirect?
I don’t know if you consider it a bypass, but header issuance does not finish the script. You should do this manually with exit after a redirect, or the script moves on: if(!isset($variavel)) {…
-
3
votes1
answer981
viewsA: How to display the value of jQuery UI Slider in a text input and update the Slider if a value is entered in the text input?
Just need to put an event to monitor when the text field had the value changed, and update the slider with this value: $("#valor-idade").change(function(){ $("#slider-idade").slider("value",…
-
27
votes1
answer19067
viewsA: How can we not close the twitter-bootstrap modal by clicking outside the area?
According to the documentation, just put the attribute data-backdrop="static" in your modal: <div class="modal fade" data-backdrop="static"> ... </div>…
twitter-bootstrapanswered bfavaretto 64,705 -
5
votes1
answer1334
viewsQ: Git accuses that ignored directory has modified content
I have the directory contents in my file .gitignore, as follows: app/dir/* But when I give a git status, git accuses the following: # On branch master # Changes not staged for commit: # (use "git…
gitasked bfavaretto 64,705 -
45
votes5
answers21909
viewsA: How do I check if an email actually exists?
Without user interaction you will only be able to check whether the email is valid (well-formed) or not. Although the SMTP protocol allows the verification of accounts, several email servers no…
-
4
votes2
answers1352
viewsA: Always presents an error when I try to use the mysqli expression
See the method signature on manual Mixed mysqli_query (mysqli $link, string $query [, int $resultmode = MYSQLI_STORE_RESULT ]) This means you need to pass the connection (which is a type value…
-
11
votes2
answers151
viewsA: Syntax error in query
The error is in using single quotes around table and column names. The correct query would be: "UPDATE $pagina SET conteudo='$conteudo' WHERE 1" However, never, never, never, never use a POST…
-
14
votes6
answers18641
viewsA: What is the difference between declaring an array with "array()" and "[]" in Javascript?
In the code you used as an example, there is no difference. However, the constructor Array can receive parameters, and depending on what is passed it behaves differently. For example, if you pass…
-
3
votes2
answers391
viewsA: mysql_query returning false
If mysql_fetch_array is returning false, is because there is no data in your table. Make sure to enter the data before doing the SELECT.
phpanswered bfavaretto 64,705 -
5
votes1
answer473
viewsA: Draw same javascript object on different canvas
You need a separate object for the image (don’t worry, it will be loaded from the cache): var image5 = new Image(); image5.src =…
-
2
votes1
answer491
viewsA: Javascript Constructor for Canvas Drawimage function
The problem is that you are running a constructor at the same time you define it (because of new, as pointed out by Gustavo Rodrigues). Thus, all the parameters you are passing are undefined. The…
-
9
votes4
answers6604
viewsA: How to extract a file extension in Javascript?
The logic to extract the extension with these requirements is to isolate the last part of the path, and check: If it is blank, it starts with a dot or does not contain a dot: returns ''. Else:…
-
2
votes4
answers601
viewsA: Internal navigation with Jquery
The link points to the outside frame (window). To point to the iframe, use a target: <a href="#" target="header-reserva-iframe" class="scroll">Reserve aqui!</a> To the target work, I…
-
20
votes4
answers552
viewsQ: How to distribute words in a fixed size area?
I have a list of words and I need to distribute them in an area of fixed dimensions so that it looks like they were randomly arranged in that space. However, I need to make sure that the words do…
-
22
votes4
answers44155
viewsA: How to test null values in Javascript
You’re right, it doesn’t make much sense. About each of the points you raised: The function is called without arguments, making date an undeclared variable (and resulting in error when evaluating…
-
1
votes3
answers629
viewsA: How to capture innerHTML from a documentFragment via Javascript?
Considering your requirements, it seems the only way would be to clone each fragment’s child: function fragHtml(frag) { var div = document.createElement('div'); for(var i=0;…
-
2
votes1
answer190
viewsA: Limit images per line using Flexbox
It seems you forgot to tell CSS that the container is multiline: flex-wrap: wrap; http://jsfiddle.net/7rz29/…
-
3
votes6
answers2374
viewsA: How to select all "empty" elements
There is no selector for that. To treat everything at once, I suggest the approach that @Gustavo Rodrigues had posted (but deleted): $('input, select, textarea').filter(function () { return…
-
2
votes4
answers1363
viewsA: How to change an element within a Less file?
Unable to change a LESS variable with Javascript. Before being interpreted by the browser, LESS is compiled as CSS (which does not support variables), and references to the variable are replaced by…
-
1
votes2
answers189
viewsA: Data overwrite to cycle for
The problem is just what you suspected: as the call ajax is asynchronous, your callbacks are being called after the end of the cycle for, when the value of i will be window.numAutoDeclaracaoISCC.…
-
15
votes1
answer2920
viewsA: Is this a correct example of Javascript inheritance?
What you are doing is not exactly inheritance, for nothing in your object John is actually inherited. Javascript heritage is given by means of an internal reference called prototype, that all…
-
6
votes3
answers787
viewsA: problems to print a double number
One more way to format the output value: double x=1; double y=3; double resultado = x/y; System.out.format("%10.1f%n", resultado);
-
7
votes2
answers579
viewsA: Why does setting a CSS property with the ! attribute not work in the . css() method?
The "real reason", I can’t say, we would have to ask John Resig, creator of jQuery. It may have to do with browser compatibility, performance, or the library’s own history (it was implemented in…
-
9
votes3
answers22986
viewsA: How to add +1 in a counter variable to each click?
One more option, using closure. This is basically what Paulo Roberto did, but with no global variable: function criaCounter(init) { var count = init || 0; return function() { count++; alert(count);…
-
9
votes3
answers4195
viewsA: How to insert an element between two elements?
In pure Javascript you can do so: var HTMLString = '<table id="teste"><tbody id="appender"><tr class="header"><td class="cod">Código</td> <td…
-
42
votes12
answers208289
viewsA: How to format date in Javascript?
For those who don’t want to reinvent the wheel, there’s the library Moments.js, that handles this and several other operations involving Javascript dates. Among the functions of Moment is the…
-
16
votes3
answers24198
viewsA: Wait for Ajax return in synchronous function
Yes, but first I need to make it clear that use ajax synchronously is highly contraindicated. The user interface will be frozen until the return of ajax. The code for this in jQuery is: var a;…
-
5
votes1
answer119
viewsA: Problem with display condition in Js
A fairly probable cause is that the property display is actually blank. A simple solution is to reverse the logic: var slider = document.getElementById('slide'); if(slider.style.display !== 'none'){…
javascriptanswered bfavaretto 64,705 -
22
votes8
answers95476
viewsA: How to check with jQuery if there is a checkbox checked?
jQuery has a shortcut to this, the pseudo-class :checked (that is part of CSS3). With this you can reduce your code well: var checado = $(obj).find("input[name='analisar']:checked").length > 0;…
-
10
votes1
answer378
viewsA: How to use escape character in CSS?
You can simply use the literal character (as noted by Emerson Rocha Luiz, the CSS file - and possibly also HTML - must be saved with the UTF-8 encoding): a:before { content: "➔"; } Or the character…
cssanswered bfavaretto 64,705 -
2
votes3
answers221
viewsA: Equivalent to jQuery’s . filter() method or Zepto in pure javascript
In the case of your example, nor would it be necessary to filter. Can be solved with a single selector: var elementos = document.querySelectorAll('p.middle'); A simple way to implement the filter is…
javascriptanswered bfavaretto 64,705 -
8
votes4
answers1480
viewsA: What is the correct way to simulate a <script> with a new language?
It is possible to monitor DOM loading using a MutationObserver. There are still support restrictions on using this (for example, in IE, it was only implemented in version 11), and I have no…
-
112
votes7
answers78990
viewsA: How does this if/Else work with "?" and ":"?
Other answers have explained how the ternary conditional operator, with good examples. It evaluates conditional expressions, in a manner similar to the if: var variavel = condicao ? valorSeTrue :…
-
1
votes4
answers1443
viewsA: SQL query that meets a parameter that is a set
There are a few ways to do this. One I quite like uses a GROUP BY and prior knowledge of how many symptoms you need to marry. An example, assuming the actual structure of your database: SELECT…
-
3
votes1
answer730
viewsA: Create a method in an involved function
You can hang the properties you want to monitor on the object/function that is returning. For example: function spy(func) { function spied(){ var args = Array.prototype.slice.call(arguments);…
javascriptanswered bfavaretto 64,705 -
3
votes2
answers326
viewsA: How does the jQuery stack (stack) work?
I looked at the source code is simpler than I thought. The stack has been implemented as a string of objects. Each jQuery object can have a property prevObject, pointing to the previous object.…
-
3
votes1
answer1290
viewsA: Conversion of ASCII code to characters does not work
My Java is very weak, but I see a problem here: for (int i= 0; i <= str.length(); i++) You are iterating an extra character. The code should be: for (int i= 0; i < str.length(); i++)…
-
1
votes2
answers388
viewsA: How to remove table of results from a Cakephp find()?
You can temporarily disassociate the other model: $this->Usuario->unbindModel(array('hasAndBelongsToMany' => array('Movimentacao'))); (Substitute hasAndBelongsToMany by the kind of…
-
16
votes2
answers523
viewsA: Why should we use Anonymous functions with jQuery instead of the function directly?
Methods waiting for a function await a reference function. For example: $("a").on("click", retornaNada); This is advantageous if you want to use the same function as Event Handler in more than one…
-
3
votes4
answers574
viewsA: Is it okay to store the password in a public class variable?
I made a related question (in English) on how to treat passwords plastered in the code. The answer I got is that it is recommended to use some kind of hash (with salt) in those passwords. The…
-
78
votes6
answers27772
viewsA: When, why and how to use the "use Strict" directive in Javascript?
As others have said, Strict mode is a more rigorous way of interpreting language, which prohibits certain practices that have always been allowed but are not recommended (such as the creation of…
-
4
votes7
answers16282
viewsA: Understanding the JSON file
As I was the one who suggested the JSON and created the confusion, I will explain myself: the JSON I posted in the other answer was invalid (already corrected), because in JSON the keys need to be…
-
6
votes3
answers243
viewsA: "Unclosure" a closure
From what I understand, you need to part of the variables of a given execution context, but does not want to keep them all in memory. A solution is to generate its function in another context,…
-
3
votes7
answers31206
viewsA: How to insert data into DB with jQuery/Javascript without using PHP?
You said in a commenting: What I intend to do is something very simple to train some things like HTML5, CSS3 and javascript, I want to make a small "database" with names of movies I’ve watched and…
-
20
votes9
answers9696
viewsA: Is it right to use the <i> tag for icons and not italics?
In HTML4, the tag <i> meant italic. Over the past decade, the web standards movement has struggled for developers to separate style structure, which is the responsibility of CSS. But it would…
-
3
votes2
answers2482
viewsA: I can’t define margin-top/bottom/right for block element, why?
The upper margin is being applied, the problem is that it collapses with the margin of the external div, and ends up being applied between the external div and the top of the page. You can see a…