0

I am working with one jQuery library that allows to open modal windows by clicking a link. The point is that I want to open the window but without clicking any link. I know it's a little strange, but it is possible to call the modal without having the trigger link (where the reference to the modal library is)?

Update: What I have tested

<script type="text/javascript">
    $(function() {
        $('a[rel*=leanModal]').leanModal({ top : 100, closeButton: ".modal_close"});        
    });
</script>

...
<!-- a rel="leanModal" href="#modal" name="modal">Link</a -->
...

<script type="text/javascript">
    $('#modal').click();
</script>
<div id="modal">
</div>

The reference to the modal div is in link, but I don't have that link and it won't be created.

Reference: leanModal.js

3
  • api.jquery.com/trigger Commented Jun 6, 2013 at 16:35
  • 1
    Google your exact question title and read through the first few results. Commented Jun 6, 2013 at 16:36
  • @Blender I did it but it did not helped me. Thank you. Commented Jun 6, 2013 at 16:50

1 Answer 1

3

Just trigger the link click where you want.

$(".myLink").trigger('click'); // or:
$(".myLink").click();

Edit: In your question you're using the wrong handler. $("modal") would look for a <modal> element. You're looking for $('#modal').

If you want to have the dialog pop up without a link at all, you should be able to set it hidden using display: none in the CSS or style attribute, and then trigger it via code anyways.

Or, you can use Fancybox for added flexibility, and they're more open about how to use their dialog boxes without attaching to a specific link, but rather any element and decide what goes inside and how to trigger it.

Sign up to request clarification or add additional context in comments.

7 Comments

or if you have some ajax loaded stuff: $(".myElement").live("click",function(){});
@TobiasHagenbeek, I'm not sure that would work? Shouldn't the callback be null in that point?
Does not work either. I understand you notice the call is from link but I am playing without that link.
Do you mean that link is generated via AJAX or something? If you call the trigger code after it's created it should work, because your'e not binding the event to it before it exists, you're looking for it after it does. You can also have the actual AJAX being retrieved have all the code you want inside, so you can trigger it whenever the AJAX is loaded and added to the document.
There is no link. It won't be created by no means. I was asking for a way to call jQuery library that is supposed to be called throught a link on a different way (if possible). Maybe is not possible at all.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.