Google+

Saturday, July 30, 2011

Dynamically create a accordion by java script and jquery


Suppose , you have to dynamically get 10 accordion or any number of accordion , there are mainly two solution : whether you create a all accordion by manually or you create that accordion dynamically .



First all create a div with any id , i create a div with accordion id .


            <div id="accordion">
            </div>

   
 Second add script to generate dynamically accordion .


   <script type="text/javascript">

        $(document).ready(function () {     
            BindEnvironments();
        });


 function BindEnvironments() {

            var text = $("#accordion");
            for (var i = 0; i < 10; i++) {
                var content = '<h5><a href="#" id="hf' + i + '" >' + i + '</a></h5>';
                content += '<div id="dv' + i + '">AAA</div> ';
                $("#accordion").append(content);
            }
            $("#accordion").accordion({
                collapsible: false,
                autoHeight: false,
                active: -1
            });
        }

</script>



Note:-Please comment and reply me.

2 comments:

  1. nice information its really very useful..
    :)
    thanks

    ReplyDelete
  2. thanks alot!! I love you!
    from korean

    ReplyDelete