'How to make a <p> clickable javascript
I currently have this block of code which prints out a list of names associated with a list of people on a team. I am trying to make the text clickable that way you are able to capture the name of the person you clicked and perform an action on a different php file passing the name of the person you clicked. How would I go about doing this
<script type="text/javascript">
$(document).ready(function() {
$("#your_teams234").change(function() {
var team = $("#your_teams234").val();
$.ajax({
url: 'functions.php',
method: 'post',
data: 'members=' + team
}).done(function(requests) {
console.log(requests);
requests = JSON.parse(requests);
$('#teammates').empty();
requests.forEach(function(request) {
$('#teammates').append('<p class="myDivs">' + request.fname + ' ' + request.lname + '</p>')
})
})
})
})
</script>
<script type="text/javascript">
$('.myDivs').click(function(){ alert($(this).text()); });
</script>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
