开发者

jQuery replace div based on rel attribute

开发者 https://www.devze.com 2023-01-24 09:39 出处:网络
I\'m trying to replace a div based on a class name and a rel attribute. <script type=\"text/javascript\">

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

精彩评论

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