Skip to main content
added 332 characters in body
Source Link
Shadow Wizard
  • 66.8k
  • 26
  • 143
  • 209

I assume you mean something like this?

<script type="text/javascript">
$(document).ready(function() {
   $("#MyLink").click(function() {
      alert($(this).closest('div').html());
   });
});
</script>

This requires you to add id to the link.

If you mean show the alert without clicking anything you'll have to explain how exactly you want it to show, meaning in response to what event?

Edit: in case you have more than one element, use class instead e.g. <a class="MyLink" ...> then have such code:

$(document).ready(function() {
   $(".MyLink").click(function() {
      alert($(this).closest('div').html());
   });
});

Using . instead of # will give all elements with that class.

I assume you mean something like this?

<script type="text/javascript">
$(document).ready(function() {
   $("#MyLink").click(function() {
      alert($(this).closest('div').html());
   });
});
</script>

This requires you to add id to the link.

If you mean show the alert without clicking anything you'll have to explain how exactly you want it to show, meaning in response to what event?

I assume you mean something like this?

<script type="text/javascript">
$(document).ready(function() {
   $("#MyLink").click(function() {
      alert($(this).closest('div').html());
   });
});
</script>

This requires you to add id to the link.

If you mean show the alert without clicking anything you'll have to explain how exactly you want it to show, meaning in response to what event?

Edit: in case you have more than one element, use class instead e.g. <a class="MyLink" ...> then have such code:

$(document).ready(function() {
   $(".MyLink").click(function() {
      alert($(this).closest('div').html());
   });
});

Using . instead of # will give all elements with that class.

Source Link
Shadow Wizard
  • 66.8k
  • 26
  • 143
  • 209

I assume you mean something like this?

<script type="text/javascript">
$(document).ready(function() {
   $("#MyLink").click(function() {
      alert($(this).closest('div').html());
   });
});
</script>

This requires you to add id to the link.

If you mean show the alert without clicking anything you'll have to explain how exactly you want it to show, meaning in response to what event?