I'm trying to get the id attr from different onclicks.
Here is the html I have.
<div id="name-1">
<a href="#" class="view">
<div>
<div id="name-2">
<a href="#" class="view">
<div>
<p>Name: <span class='name'></span></p>
<script>
$(".view").click(function() {
var id = $(".view").closest("div").attr("id");
$('.name').html(id);
});
</script>
When I click the first view I see "name-1" however when I click the second view nothing happens. Also, when I click the second name it shows "name-1". I know this is probably easy to solve but it's friday so I appreciate the help.