I have the following HTML:
<div fxFlex="48px">
<div *ngFor="let title of levelLabels"
[style.marginLeft.px]="title.xPosition+16">{{title.label}}<button
(click)="test()" style="cursor:pointer"></button></div>
</div>
When I click on the button no event is firing. Hovering over the button is not changing the cursor to hand. Any idea what is wrong with my code?
Thanks
Your button doesn't have anything inside it, so I believe it is actually impossible to hover or click it. Try adding some text in it and see if that works <button (click)="test()" style="cursor:pointer">Test text</button> or move your {{title.label}} inside the button. Because hovering your div with an empty button inside it will not work.
Related
Was wondering why when I clicked my button in html it wasn't responding later found out that it will only respond and redirect when I clicked the wording inside "Get Started" was wondering why. This is the code I'm using
<div class="main">
<div class="main__container">
<div class="main__content">
<h1>RAID 2 EARN</h1>
<h2>TECHNOLOGY</h2>
<p>We make it easy!</p>
<button class="main__btn">Get Started</button>
</div>
<div class="imgmain">
<img id="main__img" src="/IMGS/picture1.svg"/>
</div>
</div>
</div>
It is because you're actually clicking the anchor tag inside of the button and the button click doesn't have any actions associated with it. The size of the hyperlink is always only the size of its content. You should change your CSS to style your hyperlink to look like a button. Typically, you can do something like this:
<a class="main__btn" href="raid2earn.html">Get Started</a>
This way you're HTML spec compliant and your hyperlink is styled to look like a button but you're using default browser patterns to complete your action.
Your anchor tag is enclosing only the 'Get Started' text instead of the button. This way, only the text becomes a link
Actually, every html element has a job.
<a> for connecting to outer files
<button> for the inside actions
And you can style everyone as you want.
But:
if you still need to use the button and put the a inside and need to be able to click the button and do the action of the a, there are many many ways, some in html, some in css, and others in javascript.
In html, the easiest solution to your issue is to flip the elements, and make the a outside the button like that:
<a href="#">
<button>Click the button now</button>
</a>
This one is just the easiest.
And there are many others in html and css and javascript.
But again, you must use every element in its own purpose.
Sure you are putting a link tag inside a button because you want a button look and feel. just style your a element the way you want your button to look like as suggested above.
Cheers
I am trying to use one of the 'checkbox hacks' in which an accordion opens or closes when the user clicks on a label that toggles a checkbox.
The issue is that the webpage I am working on does not use labels, but rather h4 elements. So the user would be clicking on the h4 element to open/close the accordion. As far as I know, making this work directly is not possible. Or is it? I thought that maybe I could overlay an empty label over this h4 element, so that the user would be clicking on the label. Is that possible? Or is making a javascript accordion the only option here?
Here's a suggestion how to do it:
<body>
<!-- Add cursor : pointer to show the user he can click -->
<h1 onClick="myFunc()" style="cursor: pointer;">test</h1>
<script>
// Do something here
function myFunc(){
console.log("title clicked")
}
</script>
</body>
I need to create a dropdown with "change password" section in it, the dropdown is supposed to appear on click, let the user change the password and close when the button is clicked again.
This is how it looks like at the moment:
The popup closes as soon as the user clicks on it, so the user cannot update the password.
I know it might be a dumb question, but I'm new to programming and just learning..
This is what I got so far:
$('.ui.dropdown')
.dropdown({
on: 'click'
})
<div className="ui dropdown link item" tabIndex="0" href="/Account/Profile">Hi {this.props.username}
<div className="menu">
<div className="item">
<ChangePassword/>
</div>
</div>
</div>
Thank you so much in advance!
I'll just point out why this is happening for you, there's a few updates you could make to your code but I'll let you figure that out as you go :)
Firstly, onClick() will trigger whenever a mouse click occurs on the element you've set it on, as well as all the children of that element:
e.g (this is just semi-psuedo)
<div onClick={} >
<button />
<button />
</div>
In this case, onClick will trigger when you click the parent div which, on the page, will be wrapping both buttons.
If you've set the method to trigger when the ui-dropdown component is clicked, this will occur whether the drop down is open or not.
The usual way to do this would have two separate components:
Button (The thing you click on to open the dropdown)
The Dropdown
If you put the onClick function on the Button element, but have it activate the Dropdown element, your problem will be solved :)
I am trying to be as clear as possible without just downright fixing it for you, let me know if you need any more clarity!
I am using ReactJS with React-Bootstrap and am rendering the following content:
<div onClick={this.openModal.bind(this)} className="container">
<div className="content">
<div className="list">
...
</div>
<Button onClick={this.deleteContent.bind(this)}
className="delete-content">X
</Button>
<Modal show={this.state.showModal}
onHide={this.closeModal.bind(this)}
className="edit-content">
...
<Button onClick={this.closeModal.bind(this)}
className="close-modal">X
</Button>
</Modal>
</div>
<div>
In <div className="content">, I am rendering a set of components, and when you click on the <div className="Container">, it will open the Modal so you can edit the container's contents. There is a button to delete the container all together, which is inside the <div className="container">, as many containers will be rendered iteratively.
I am controlling whether the Modal is open with the component's state, where this.openModal() and this.closeModal() simply toggle a boolean that determines if the Modal should be shown (this.state.showModal).
My problem is: when I click the Button with className="delete-content" in the container, it also registers a click to open the Modal, because <div className="container"> has an onClick property. Thus, when I delete containers, the app gets stuck thinking the Modal is open, even though it's not.
My first idea to fix this is to move the onClick property from the <div className="container"> to <div className="list">, but I would like all of the space around the <Button className="delete-content"> to be clickable, and if I move it to list it will restrict the clickable area.
Is it possible to somehow implement when the delete-content Button is clicked to temporarily disable the onClick property of the <div className="container">? Or any other ideas/fixes?
It happens because of event propagation. To fix the problem you need to use stopPropagation on the event object.
handleDelete(event) {
event.stopPropagation()
this.deleteContent()
}
<Button
onClick={this.handleDelete.bind(this)}
className="delete-content">X
</Button>
I am attempting to alter the hover functionality of a KendoUI button. The HTML looks like the following:
<div class="div-vertical-delimitor div-float-left"></div>
<a id="a-draw-point" class="k-button single" title="Point">
<img id="img-draw-point" src="../Images/DT_DrawPoint.png">
</a>
</div>
The issue is, I'm not seeing a k-state-hover class being activated when I hover over the button. However, the button does change when hovering over it.
When hovering over other objects on the page such as toptab links I see the k-state-hover being applied when mousing on top of the link.
Any help would be appreciated. I'm new to CSS and KendoUI.