I'd 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 MUST NOT use a script like this:
<script type="text/javascript">
jQuery(document).ready(function(){
$("#myLink").fancybox({href : 'myPage.php'});
});
</script>
I want to trigger a fancybox from an <a>
onclick element. But into this onclick function, it MUST have the 'href' from fancybox, exactly as I wrote above. But as I wrote, it doesn't work. Please help :)
I'd 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 MUST NOT use a script like this:
<script type="text/javascript">
jQuery(document).ready(function(){
$("#myLink").fancybox({href : 'myPage.php'});
});
</script>
I want to trigger a fancybox from an <a>
onclick element. But into this onclick function, it MUST have the 'href' from fancybox, exactly as I wrote above. But as I wrote, it doesn't work. Please help :)
-
I MUST NOT use a script like this
.... why? – JFK Commented Aug 4, 2012 at 8:19
2 Answers
Reset to default 1after the document ready, bind the button click event.
jQuery(document).ready(function(){
$("#myLink").click(function() {
$(this).fancybox({href : 'myPage.php'});
});
});
then there is no need for javascript code in your element.
<a href="#" id="myLink">Open ajax content</a>
Check this links for the jQuery click function and more about observer pattern
try
$("#myLink").click();
it should trigger the onclick
event.