Posts by Sergio • 133,294 points
2,786 posts
-
9
votes2
answers5931
viewsA: How to hide a visible sub-menu by clicking on another JS menu?
The quickest way to fix your code is to add a for loop to make all menus invisible and then show only what should be visible: function toggle_visibility(id) { var e = document.getElementById(id);…
-
22
votes4
answers13539
viewsQ: How to prevent a click on a link/anchor or tied event element
In the case of a link: <a href="http://www.google.com">Google</a> or in the case of another element having an event tied with addEventListener, what alternatives exist to prevent the…
-
23
votes4
answers13539
viewsA: How to prevent a click on a link/anchor or tied event element
A variant is via CSS, using Pointer-Events. I discovered this way only this week. Hence the post here. Thus using in CSS pointer-events: none; mouse clicks will be ignored. This alternative is +/-…
-
6
votes2
answers6568
viewsA: "placeholder" of "textarea" does not appear
In the case of tag textarea, to the placeholder function, tag opening and closing must be on the same line and no spaces. In your case the textarea thinks the line break is content and the…
-
8
votes5
answers704
viewsA: Event is not tied to the element
The best solution I see is to delegate the click via Document (or a relative who has been present since the page uploaded). So you can use: $(document).on('click','#refresh_abertos',function(){ //…
-
5
votes1
answer429
viewsA: Add "thead" to a table created with createelement
You can use it like this: var header = context.createTHead(); var row = header.insertRow(); Example With jQuery it is simpler since it is allowed to create elements directly and add them to the…
-
9
votes2
answers629
viewsA: Why does jQuery fadein not work if the element has zero opacity?
The jQuery does not fade to opacity, example I found a resposta interessante (in English) that talks about it. And interestingly the jQuery consider opacity:0 as not hidden! <div style="opacity:…
-
5
votes3
answers14251
views -
6
votes3
answers471
viewsA: Add custom timezones in PHP?
Maybe what you could use, beyond the possibility that the mgibsonbr indicated, is the Modify: So I could change the Datetime object to give the modified date with the difference inserted. Example:…
-
3
votes3
answers1076
viewsA: Is anchoring a TR possible?
Yes it is possible with javascript. Inserting links between table and tr is not correct syntax, so the path is actually javascript. You can add an "Event Handler" that looks for clicks within the…
-
2
votes1
answer1360
viewsA: Period filtering in data type inputs
Try it like this: function decimas(n){ return n > 9 ? "" + n: "0" + n; } function getDate(m) { var data = new Date(); var diffAno = 0; var mesAnterior = data.getMonth() - (m === undefined ? 1 : m…
-
15
votes5
answers5370
viewsA: How to apply ! CSS import via jQuery?
The best way to apply CSS rules is always by using classes. So it’s best to define a class in CSS .minhaClasse { width: 50px!important } and add the class with: $('#elem').addClass('minhaClasse');…
-
4
votes4
answers13879
viewsA: How to detect if an HTML element is empty?
You can use .html().length to check the size of the element content. Code example: <div id="minhaDiv"></div> <div id="minhaDiv2">2</div> var div =…
-
7
votes2
answers1010
viewsA: How can I simulate a placeholder using a label?
I don’t see how to do this only with CSS since you want to change an element when you do focuson the other and they having no degree of kinship among themselves. So my suggestion is to use…
-
11
votes1
answer946
viewsA: How to get multiple of some PHP value?
What you need is the function Ceil(), which rounds up values. So you can use: $valorRetornado = ceil($seuValor / 4); For example: echo ceil(1 / 4); // dá 1 echo ceil(4 / 4); // dá 1 echo ceil(5 /…
-
3
votes3
answers427
viewsA: How can I include the 'Submit' button in the 'POST' matrix generated by 'serialize'?
The first way that occurs to me is to add a hidden input after checking and before serialize is called. if (mandatoryFieldsFilled($this)) { var inputEscondido =…
-
31
votes3
answers5488
viewsA: How to use the current value of a variable in a more internal function?
Note: In the modern version of Javascript (from ES6) this problem no longer happens if we use let in the for (let i = 0; ... More about Let, cont and var here. Answer to the question code: The…
-
10
votes8
answers14487
viewsA: How to create a copy of an object in Javascript?
Copying an object (with all its attributes and methods/functions) is not a single response task. In the case of more complex objects I recommend the use of a library such as the Mootools which has a…
-
43
votes7
answers3681
viewsQ: What are the implications of not declaring variables in PHP?
In php I can do this without declaring/defining variables: echo($foo); //resolve: vazio, sem nada $foo++; echo($foo); // resolve: 1 Using var_dump() the same gives, respectively NULL and 1. If I use…
-
7
votes2
answers531
viewsQ: How to avoid conflict between jQuery and Mootools
Good practices to avoid conflicts between jQuery and Mootools libraries? This example makes the mistake Uncaught TypeError: Object [object Object] has no method 'fade' //codigo Mootools…
-
10
votes2
answers531
viewsA: How to avoid conflict between jQuery and Mootools
Since both Mootools, jQuery (and even Prototype) use the dollar $, dollar is the problem that needs to be solved and the source of conflict between the two libraries. mootools uses the $() to select…
-
2
votes2
answers230
viewsA: How to avoid animation of elements that will not fit in the width of the screen?
Here is a suggestion: var wrapperWidth = $('#balls').width(); $('#balls img').each(function(){ $(this).css({ "top" : "-" + $(this).height() + "px", "left" : Math.floor(Math.random() * wrapperWidth)…
-
14
votes4
answers3358
viewsA: How to create an element and after a few defined seconds remove it?
You can use it like this: var aviso = '<p id="lblAviso">Salvo com sucesso</p>'; var destino = $('#destinoAviso'); //codigo que você quer: destino.append(aviso); setTimeout(function(){…
-
68
votes8
answers67841
viewsQ: How to export an HTML/PHP page to PDF
How to export an HTML page to a PDF file? Having a standard document where you can change variables within that template and then export that page to a PDF file in A4 format, without spoiling the…
-
6
votes2
answers3548
views -
6
votes2
answers3548
views -
5
votes4
answers12949
viewsA: Return Array with name of all files in directory
As already mentioned this task is difficult/impossible on the client side, server-side languages are the correct way. But since you ask, and assuming that the directory is on the same server and…
-
8
votes9
answers27569
viewsA: How do I read Javascript URL values (Querystring)?
To remove information from the url you can create an object with pairs of chave:valor of each url parameter. In this case, it is seen that the parameter separator is the symbol & the values…
-
6
votes10
answers68840
viewsA: How to make a <div> occupy the entire page width but leave a gap of a few pixels on each side in CSS?
The problem here is that you want to have the top menu (#header) with position: fixed and this makes CSS consider 100% of the maximum screen width. So the solution I see is to use percentage…
-
6
votes2
answers1505
views -
12
votes1
answer1328
viewsQ: How to use a bracketed name (square brackets) in a jQuery selector?
What is the best way to call an element that has straight parentheses in the name, using jQuery?. HTML <div name="name[1]"></div> jQuery $('div[name=name[1]]'); //errado?…
-
16
votes1
answer1328
viewsA: How to use a bracketed name (square brackets) in a jQuery selector?
The first example $('div[name=name[1]]'); is incorrect, and gives the error unrecognized expression: div[name=name[1]]. The other options are correct, although for slightly different reasons.…
-
16
votes6
answers2089
viewsA: How to change the bottom lines of a table alternately? With support for older browsers
The solution can be simply with CSS using: tr:nth-child(even) td { border-bottom: 3px solid red; } tr:nth-child(odd) td { border-bottom: 3px solid green; } Example NOTE: These are properties of CSS3…
-
10
votes3
answers3264
viewsQ: Invert the order of a jQuery widget list
How to reverse the order jQuery iterates an array of elements? In this case what I would like is to invert the contents of the items within the array. For example: <ul> <li>Item…
-
6
votes3
answers3264
viewsA: Invert the order of a jQuery widget list
More options: Option A: $($("ul > li").get().reverse()).each(function (i) { $(this).text( 'Item ' + (++i)); }); Demo here Option B Using the jQuery combination with the method re-verse…
-
5
votes4
answers2572
viewsQ: Expandable menu CSS transitions
Having an expandable menu like using the CSS transition to open/close at the same time the part that is open and the part that is closing? The problem does not arise if the menus are the same size…