0

I have jQuery Ui tabs like this

<div id="tabs">
    <ul>
        <li><a href="#tabs-1">Preloaded</a></li>
        <li><a href="ajax/content1.php">Tab 1</a></li>
        <li><a href="ajax/content2.php">Tab 2</a></li>
        <li><a href="ajax/content3-slow.php">Tab 3 (slow)</a></li>
        <li><a href="ajax/content4-broken.php">Tab 4 (broken)</a></li>
    </ul>
    <div id="tabs-1">

    </div>
</div>

in the JavaScript I have

$(document).ready(function() {
    $( "#moreinfotabs" ).tabs();
    $('a').click(function(){
        alert("asdas");
    });

When content1.php for example is loaded, I want to handle click on the links in content1.php and to alert something but It's not happen. How to do that ?

PS: I wrote for a link, whatever I want to use with a.classname....

0

1 Answer 1

1

For dynamically generated elements, events should be delegated, from one of static parents of the element, or document object.

$(document).on('click', 'a', function(){
    alert("asdas");
});

Please note that you haven't closed the document ready handler:

$(document).ready(function() {
    $( "#moreinfotabs" ).tabs();
    $(document).on('click', 'a', function(){
        alert("asdas");
    });
}) // <--
Sign up to request clarification or add additional context in comments.

2 Comments

+ 1 and just minor observation: the OP forgot to close }); in his/her document.ready :)
@Tats_innit Thanks bro, yes, I forgot to mention that :)

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.