Using <a> onclick to open ajax content in fancybox
I would like to do something like this:
<a href="javascript:void(0);" id="myLink" onclick="$(this).fancybox({href : 'myPage.php'});">Open ajax content</a>
Note that I SHOULD NOT use the script as follows:
<script type="text/javascript">
jQuery(document).ready(function(){
$("#myLink").fancybox({href : 'myPage.php'});
});
</script>
I want to run fancybox from an <a>onclick element . But in this onclick function, it MUST have a "href" from fancybox, exactly as I wrote above. But, as I wrote, this will not work. Please, help:)
+5
2 answers
after the document is ready, bind the button click event.
jQuery(document).ready(function(){
$("#myLink").click(function() {
$(this).fancybox({href : 'myPage.php'});
});
});
then in your element there is no need for javascript code.
<a href="#" id="myLink">Open ajax content</a>
Mark these links for the jQuery click function and more about the observer schema.
0