Hormigas
Hormigas

Reputation: 1449

jquery .trigger() doesn't seem to work

This is my code :

$(document).ready(function () {
//alert("wa");
$("#wis").trigger('click');
$("#wis,#wib").click(function (){
    alert("clciked");
    if(!$(this).hasClass("dealsb")) {

        $(".dealb").removeClass("dealsb");
        $(this).addClass("dealsb");
        var id=$(this).attr("id");
        $.post("deals.php",{'req':id},function(data){
            //alert("works");
            $("#deals").html(data);});


        }

    }); 
});
</script>
<div id='wib' class='dealb'>What I've Purchased</div><div id='wis' class='dealb'>What I've Sold</div>
<div id="deals" style='position:absolute;left:0px;top:100px;width:600px;height:300px'></div>

Here $("#wis").trigger('click'); doesn't seem to work. When I click #wis or #wib though, the alert gets fired off and everything runs perfectly.

Upvotes: 0

Views: 1411

Answers (1)

Brad Mace
Brad Mace

Reputation: 27886

You're triggering it before you add the click handler, so the behavior you're seeing makes perfect sense. Move the trigger to the end of your <script> tag and you should be set.

Upvotes: 3

Related Questions