0

I just wanted to ask why $(this) selector doesn't work inside $scope functions in Angular JS + jQuery.

I have this sample code:

[Javascript]

$scope.startTimer = function() {
     $(this).hide();
}

[HTML]

<button ng-click="startTimer()">

I've tried doing it like this but still doesn't work:

[Javascript]

$scope.startTimer = function(btn) {
     $(btn).hide();
}

[HTML]

<button ng-click="startTimer(this)">

Anyone knows how to fix this? Sorry for the noob question.

2 Answers 2

4

do it with angular way...

[HTML]

<button ng-click="startTimer()" ng-hide="btnHide">

[Javascript]

$scope.startTimer = function(btn) {
     btnHide = true;
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can do this a scope variable inside the markup in angular

<div ng-init="hideButton:false">
    <button ng-click="hideButton=true" ng-hide="hideButton">
</div>

Working Demo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.