开发者

jQuery replace div based on rel attribute

I'm trying to replace a div based on a class name and a rel attribute.

   <script type="text/javascript">

        $(function () {

            $('.special_button').click(function () {

                var num = $(this).attr('rel');

                $(button with class .value_butt开发者_如何学Goon and rel=num).replaceWith("<div class='value_button' >" + $(this).val() + "</div>");
                $('div.content_slide').slideUp(600);
            });
        });

    </script>

How would you do this?


Try this:

$(function () {

   $('.special_button').click(function () {

       var num = $(this).attr('rel');

       $('.value_button[rel="' + num + '"]').replaceWith("<div class='value_button' >" + $(this).val() + "</div>");
       $('div.content_slide').slideUp(600);
   });
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜