Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-click doesn't work when the button is floated to the right

Ok this is such a strange one.

I am working in an Angular Project, I have a button with a ng-click attached. It doesn't fire. If I remove the css that floats the button to the right, then it works fine.

HTML:

<button id="btn" ng-click="myFunction()">Name</button>

CSS:

button {
    float: right;
    background-color: green;
    color: white;
}

Javascript / Angular Controller:

app.controller('HomeController', function($scope) {

 $scope.myFunction = function() {
  console.log('Hello World');
 };

});

Simply changing the CSS to:

button {
    background-color: green;
    color: white;
}

Makes it work again

like image 776
dylankbuckley Avatar asked Sep 10 '25 14:09

dylankbuckley


1 Answers

I think when you float it to the right, some other html is on top of your button and it's preventing you from making the click.

Add a z-index: 9999 to your button's css

Hope it helped :)

like image 192
atefth Avatar answered Sep 12 '25 03:09

atefth