Question

I am adding <li> and checkBoxes dynamically in web page i am usinh JQuery Mobile but after adding it cannot view properly i tried with $('#contactList').listview('refresh') but it shows error that listview is not a function Here is my HTML Part

<ul data-role="listview" data-inset="true" data-filter="true" data-filter-placeholder="Search" id="contactList">
                </ul>

and JS Part that i add dynamically is

$('#contactList').append('<li>\
                    <input type="checkbox" name="'+contactId+'" id="'+contactId+'" class="custom" />\
                    <label for="checkbox-5a">\
                        <span class="span2 contact-name">\
                        '+contactName+'\
                        </span>\
                        <span class="contact-image">\
                            <img src="'+contactImage+'"/>\
                        </span>\
                    </label>\
                </li>')

Now how i refresh both li and check boxes so they looks correctly

Update:: My Page Head is like this

<script src="js/jquery-1.9.1.min.js"></script>                      <!-- Scripts n CSS  -->
<script src="js/jquery.mobile-1.3.1.min.js"></script>               <!-- for J Query Mobile -->
<link rel="stylesheet" href="css/jquery-ui.css" /> 
<link rel="stylesheet" href="css/jquery.mobile-1.3.1.min.css" />


<script src="js/jquery-ui.js"></script>

<!-- For BootStrap -->

<link href="css/bootstrap.css" type="text/css" rel="stylesheet"/>
<link href="css/bootstrap-responsive.css" type="text/css" rel="stylesheet"/><!-- Must Same Order -->

<!-- HTML5 shim for IE backwards compatibility -->
<!--[if lt IE 9]>
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

<!-- User Generated JS Files -->
<script src="lib/work-space.js"></script>
<script src="lib/contactsFile.js"></script>
Was it helpful?

Solution

You should use same name in label-for as the checkbox name

your code is

$('#contactList').append('<li>\
                <input type="checkbox" name="'+contactId+'" id="'+contactId+'" class="custom" />\
                <label for="checkbox-5a">\
                    <span class="span2 contact-name">\
                    '+contactName+'\
                    </span>\
                    <span class="contact-image">\
                        <img src="'+contactImage+'"/>\
                    </span>\
                </label>\
            </li>')

But you should write this

$('#contactList').append('<li>\
                <input type="checkbox" name="'+contactId+'" id="'+contactId+'" class="custom" />\
                <label for="'+contactId+'">\
                    <span class="span2 contact-name">\
                    '+contactName+'\
                    </span>\
                    <span class="contact-image">\
                        <img src="'+contactImage+'"/>\
                    </span>\
                </label>\
            </li>')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top