The classic way to access an element would be:
<div id="myId"></div>
<script type="text/javascript">
$(document).ready(function(){
$('#myId').something();
});
</script>
Let alone the many times when there is no clear id to use to access an element, where we end up using the class attribute's value(s), but we can never be sure if there is more than just one such element in the page.
After writing this or similar code thousands of times, i got to wonder:
Is there a way to use context to directly reference a HTML element?
I'm thinking of something like this:
<div>
<script type="text/javascript">
$(document).ready(function(){
$.getContext().something(); // accessing the encapsulating div
});
</script>
</div>
Or anything similar?