I'm using following code to open a Modal in reactJS without any click:
window.$('#codeEmbedModal').modal('show')
But it is not opening a Modal. Am I doing anything wrong here? I used this way after looking at one of these answers
I'm using following code to open a Modal in reactJS without any click:
window.$('#codeEmbedModal').modal('show')
But it is not opening a Modal. Am I doing anything wrong here? I used this way after looking at one of these answers
I guess you are using bootstrap modal. then you need to trigger the modal on hover or on load using jQuery.
$("#button").hover(function () {
$('#modal').modal({
show: true,
backdrop: false
})
});
also change css for modal
position: fixed; to position: absolute;
and change css as per need .
function Example() { const [show, setShow] = useState(false);
const handleClose = () => setShow(false); const handleShow = () => setShow(true);
return ( <> Launch demo modal
<Modal show={show} onHide={handleClose}>
<Modal.Header closeButton>
<Modal.Title>Modal heading</Modal.Title>
</Modal.Header>
<Modal.Body>Woohoo, you're reading this text in a modal!</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose}>
Close
</Button>
<Button variant="primary" onClick={handleClose}>
Save Changes
</Button>
</Modal.Footer>
</Modal>
</>
); }
render();