开发者

Adding div using ajax and jQuery

开发者 https://www.devze.com 2023-02-14 21:16 出处:网络
How would I create a div that when clicked sends an ajax call to a jsp page to replace the content of the div th开发者_StackOverflow中文版at has been clicked while adding a css class to the changed di

How would I create a div that when clicked sends an ajax call to a jsp page to replace the content of the div th开发者_StackOverflow中文版at has been clicked while adding a css class to the changed div?


<div id="foo"></div>

and then:

$('#foo').live('click', function() {
    $(this).load('/bar.jsp', function() {
        $('#foo').addClass('foobar');
    });
});


the div in the view:

<div id="a" class="a" onclick="clickFunc()">...</div>

the javascript function:

function clickFunc() {$("#a").load("whatever.jsp"); $("#a").addClass("newClass");}

Hope this is what your looking for.

0

精彩评论

暂无评论...
验证码 换一张
取 消