So i am trying to create an alert message in react and i need it to close when s
ID: 3594851 • Letter: S
Question
So i am trying to create an alert message in react and i need it to close when someone presses the ' x ' however i'm not sure how to go about coding it...
There are three separate messages in the alert box and i want the user to have the option of closing each alert in the box individually..so when the 'x' is pressed only its parent <li> is closed. if i press the 'x' on the first alert i will still have the remaing two.
the following is my class and i am using react:
class AlertPopup extends React.Component {
function
render () {
const messages = ['Here is an alert message ...', 'Here is a second alert message ...', 'Here is a third alert message ...'];
const listItems = messages.map((message) =>
<li>{message} </li>
);
return(
<div style={style.alert}>
<ul>{listItems}</ul>
</div>
)
}
}
Explanation / Answer
This the Html here I have given three alerts in the single alert box you can close the specific alert or all alerts at once
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Alert Example</h2>
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Click Here to open alerts</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Alert</h4>
</div>
<div class="modal-body">
<div class="alert alert-dismissable">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
Here is your first alert
</div><div class="alert alert-dismissable">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
Here is your second alert
</div><div class="alert alert-dismissable">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
Here is your third alert
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.