Offset() not working on button click [closed] - javascript

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
I want the window to scroll down to a certain div on a button click.
$('button').click(function(event){
var offset = $('div').offset();
event.stopPropagation();
$(window).scrollTop(offset.top);
});
When I input this code in the console, it works perfectly but then doesn't work in the actual browser test.

I wrapped it in a setTimeout function and that seemed to work.

Related

How do I click the clickable element in front? [closed]

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
I have two clickable elements, one in front of the other. Whenever I try to click the one in front, it thinks I click both. How do I make it so that it only clicks the one in front? HTML, CSS, JAVASCRIPT
use event.stopPropagation
front.addEventListener("click", function(e) {
e.stopPropagation();
...
});

When using $(document).on("click",".class",function(){ } how do i reference the button that was clicked? [closed]

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 4 years ago.
Improve this question
$(document).on("click",".gbut",function(){
console.log(this.getAttribute("data-X"));
Each button has a data-x attribute and I need to be able to get the button that was clicked. Using function(this) doesn't work, and using console.log($(this).getAttribute("data-X")); doesn't work. I've searched a lot but there is no solution for using on("click","class",function()...
You could use jQuery's built-in data method:
console.log($(this).data("x"));
See the jQuery docs

JS: the document.write method doesn't work with double minus and double plus, why? [closed]

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
I tried:
document.write(15--);
document.write(++15);
and nothing show in the browser... the console gave me a red sentence.. why?
Do this instead:
var number = 15;
++number;
console.log(number);

How to make a DIV pop out from nowhere Jquery? [closed]

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
So I have a game where I want to show two numbers. But I want these numbers to come out from nowhere, perhaps from the button of the screen and they travel up and then disappear.
I was looking through the Jquery website, but I couldn't find anything similar.
Heres an example that i just wrote:
$(document).ready(function() {
$("button").click(function(){
$('.count').html(parseInt($('.count').html())+1);
//allow time for animation to finish before next click
$('button').hide();
window.setTimeout(function(){$('button').show();},3000);
$("div").css("bottom","-20px");
$("div").animate({bottom: '1200px'}, 2000);
})
});
https://jsfiddle.net/xop36gcs/4/

Angular js : ng-click-active not triggered [closed]

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 this div with ng-click event. The function works perfectly. But the ng-click-active class is not added to the div.
How is that possible?
Thanks.
ng-click-active will only appear when the ngTouch module is being used. For more information on ngTouch, refer to the docs here: https://docs.angularjs.org/api/ngTouch

Categories

Resources