First Case:
<div>
<a href="#" onclick="doIt(this)">some job</a>
<div>
i can do:
<script>
function doIt(caller){
alert($(caller).closest('div').html());
}
</script>
Second Case:
<div id="divId">
....
</div>
i do
<script>
alert($("#divId").html());
</script>
how can i apply first case mecanism to second case with out onclick(this)?
more details about question:
First case, as i use of anchor onclick, i can get action source then it’s parent.
Second case, on the other hand, there is div block and after script block. they are rendered in the page, consequence there is no click event.
i need some thing:
$(this).closest(‘div’).html()
but it doesnt work
I assume you mean something like this?
This requires you to add
idto 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:Using
.instead of#will give all elements with that class.