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 7 years ago.
Improve this question
I'm testing some javascript on jsfiddle and for some reason I can't get a function to fire on a button click. Any advice?
jsfiddle link
In the Frameworks & Extensions panel, set onLoad to No wrap - in <body>.
It took me a while to figure this out.
You have configured JSFiddle to wrap the code in an onload event handler. Consequently the function you are trying to call onclick is out of scope.
Don't use intrinsic event attributes. Use jQuery's (since you are using jQuery already) event binding instead.
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 2 years ago.
Improve this question
So, I have an array with 200 items called "icone", and when I use this code:
icone.attr('src', 'img/known.svg');
All items change according to what is in the code.
But how do I do if I want to change only 1 of the items in this array, and not all 200?
I tried with:
icone[0].attr('src', 'img/known.svg');
But the console returned "icone[0].attr is not a function".
Any ideas on how to make this work?
Thanks!
If it is absolutely necessary to use jQuery in this case. You can do this:
$(icone[0]).attr('src', 'img/known.svg');
In case it is not, you can do it as the other answers say.
Once you do icone[0], you're dealing with a raw node, not a jQuery "wrapper." That raw element does not have an .attr function.
As Ouroborus suggests, just set the attribute directly by doing icone[0].src = ....
(If Ouroborus submits an answer in addition to their comment, you should mark it as accepted, not this answer. I just wanted to explain why what you're doing doesn't work.)
EDIT: Interestingly, icone.first().attr(...) does work, because it does wrap the first element with a jQuery wrapper.
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 add my TRIGGER DIV A over $(".DIVB").html(data); from a AJAx Responsebut when i now want to trigger some code over the $(".TRIGGER DIV A").click(function() it isnt working. Can someone explain me why ? And is there a Way to fix this or is there a working arround ?
It looks like you're using jQuery's .click(). If HTML is added dynamically to the DOM, you need to bind the click event to the element after it has been added. Otherwise, when $(".TRIGGER DIV A").click(handler) runs and jQuery looks for the element to bind, it isn't able to find it.
You may consider using .delegate() instead. This ensures that the event is bound to all elements relevant to the given selector regardless of when it is added to the DOM. You can find the documentation for usage here: http://api.jquery.com/delegate/
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
So, i am in the midst of making a little website where you can calculate right angled triangles. Y'know, just for the fun of it.
Atm, i'm testing the real time calculation of the different html forms, however, i can't figure out why the form for cathetusB isn't updating.
Any help is appreciated!
This is how all the forms are set up: <input type="number" step="0.01" id="someID" onkeyup=calculate();>
The JS code messed up when i tried to paste it in, so here's a fiddle!
EDIT: Added all the code to the Fiddle!
You have configured JSFiddle so that the code runs in an onload event handler.
The functions are therefore scoped to that handler function.
They are not globals.
They are not accessible to your intrinsic event handlers.
Configure JSFiddle to place the JS in the body instead of onload and the code works.
It would be better to replace your intrinsic event handler attributes with programatic event binding.
Be careful when using this :
<input type="number" step="0.01" id="cathetusA" onkeyup=calculate();>
If you are using the same id with every form things your code will not work.
Id must be unique for every object
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 an issue with my website:
http://td.lbmedia.pl
After clicking on menu's link page smoothly reloads using ajax but... the foundation javascripts are going down. Can anyone suggest me what is the problem?
The issue is event handlers being destroyed after ajax page load, one way to solve the issue is (since I couldn't find the documentation for that plugin) using global ajax event handlers
$( document ).ajaxComplete(function() {
$(document).foundation();
});
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've created an eBay listing and it work's correctly on eBay.
But I have an issue. The listing's are listed via 3rd party software and that software has their own JS for changing the images. And it doesn't work with my scripts. I use jQuery.
Can anyone advice a simple method to swap the image src on click event?
For example: Leave as it is, but overwrite the JS. Now it is set up to listen for mouse hover. Can I write a new script so when clicked it would swap the images?
Here is the link to the listing: Listing template here
To change src attribute of an image :
$('#myImage').click(function(){
$(this).attr('src', 'myNewImage.jpg');
});
To stop listening to the mouseover event :
$('#myTargetWhichHasAnEventAttached').off('mouseover');
Edit to answer the comment :
$('.image_small_js').off('mouseover'); // supposed that the mouseover event is attached on .image_small_js
$('.image_small_js').click(function(){
$('#bigpicture').attr('src', $(this).attr('src')).hide().show(); // .hide().show() makes the change effect more smoothy... can be used with timers
});