Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Adding this line of code $("#locate-me-button").click(loadLocation()); breaks my entire JavaScript code file even if I don't click the #locate-me-button element. When this line is commented out the entire file works perfectly again. Why would that be?
You are invoking the function as passing its return value to event handler, just pass the function reference to .click()
$("#locate-me-button").click(loadLocation);
//^ () is removed
The another way (at least for case that you have parameter):
$("#locate-me-button").click(function(){
loadLocation();
});
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have a slight problem with this online code editor. When I launch my snippet, it only works one time. If I try to bring any modification to the code, it crashes for unknown reasons.
https://playcode.io/313059?tabs=console&script.js&output
Any clue of what is going on here?
I just checked and I think that your code is executing while the editor is not loaded yet. Wait for the document or window to be loaded and then execute the code as following:
$( document ).ready(function() {
var block = document.getElementById('block');
var block_scale = window
.getComputedStyle(block, null)
.getPropertyValue("transform");
var matrix = block_scale.match(/\d+(?:\.\d+)?/gm);
console.log(matrix[0]);
});
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
If I try the code below on the console in Chrome, it is working. But the code is not working in my Javascript extension in Chrome.
var region = document.getElementById("physicalDeliveryOfficeName");
region.removeAttribute("onchange");
Any thoughts what am I doing wrong? Tried to add this line in my function and on the top of my script but it is not working.
This is due to the execution environment that it is isolated in a Chrome extension.
You have to inject the code into the page to do modify the page context handlers.
Please see Insert code into the page context using a content script
It works in console because the dom has loaded. Wrap your code in an event handler.
document.addEventListener("DOMContentLoaded", function(event) {
var region = document.getElementById("physicalDeliveryOfficeName");
region.removeAttribute("onchange");
});
https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm learning js now. Testing this code to stop the refresh of the input option, but this isn't working
$(document).ready(function(){
$(".formulario-cadastro").submit(funtion(){
return false;
});
});
You have a typo in function word. You need to prevent default. Try this:
$(document).ready(function(){
$(".formulario-cadastro").submit(function(e){
e.preventDefault();
});
});
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have wrote following code example:
html:
<input type="checkbox" name="terminal" class="all" data-terminal-id="9800" >
javascript:
function checkRightBarVisibility(){
if(this.checked){
alert('checked');
}
}
$('input[name=terminal]').change(checkRightBarVisibility);
http://jsfiddle.net/o9ovnkxv/6/
This code works as expected.
But in my real code I have same javascipt code but I don't see alert.
I have not ideas how can it possible.
debug information:
bigger picture(http://i.stack.imgur.com/ADXB5.jpg)
Please help me to find the mistake.
P.S.
full code is very huge thus I didn't post it.
update:
I tried following in debug:
I wrote following row:
$('input[name=terminal]').change(checkRightBarVisibility);
After it I have seen alert 1 time.
But only one time.
If your inputs are being added dynamically then you should use delegation:
$('body').on("change", 'input[name=terminal]', checkRightBarVisibility);
(In jQuery, how to attach events to dynamic html elements?)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I'm working on this website: link
Everything works in the modern browsers, but in IE8 if I click on a plus sign in the left menu, I get an error.
The error is in the 52. line of this js: js
content = $(link).parent();
Error is
Object doesn't support property or method
From seeing your script,
togglemenu($(this));
function togglemenu(link){
content = $(link).parent();
...
...
}
you can directly have
content = link.parent();
Well content is not defined anywhere that I can see, maybe that is the problem?
Try this-:
$(link).closest('your closest parent')
Documentation=http://api.jquery.com/closest/