Msencenb
Msencenb

Reputation: 5104

Changing content within fancybox using jquery.html()

So I have a fancy box with a link in it.

fancybox content:

<a href="#" class="precilink">preci description</a>
<div id="precitext">
   text changed by clicking preci
</div>

Now I have this jquery up top:

    $(".precilink").click(function(e){
        e.preventDefault();
        $('#precitext').html("hello");
    });

But nothing happens, although in the dom the precitext id html gets change. How do I tell fancybox to reload?

Upvotes: 2

Views: 3170

Answers (3)

gorgi93
gorgi93

Reputation: 2535

You should use live event because javascript is dynamical inserted in DOM.

$(".precilink").live('click', function(e){
    e.preventDefault();
    $('#precitext').html("hello");
});

Hope this helps

Upvotes: 1

Johnny Craig
Johnny Craig

Reputation: 5000

for normal useage of fancybox, the link must point to the div. it may not be necessary in this case, but its worth a shot

<a href="#precitext" class="precilink">preci description</a>

Upvotes: 0

Ulmo
Ulmo

Reputation: 1

Try using .text instead of .html.

$(".precilink").click(function(e){
        e.preventDefault();
        $('#precitext').text("hello");
});

Upvotes: 0

Related Questions