jquery - apply loaded CSS to dynamically created HTML -
jquery - apply loaded CSS to dynamically created HTML -
i'm adding html content dynamically using code on jquery mobile listview :
this code beingness loaded in index.html
file withing #page
container
<meta charset="utf-8"> <link rel="stylesheet" href="css/pages/notifications-list-view.css"> <div id="notifications-wrapper"> <div class="notifications-content"> <div data-role="navbar" id="navbar" class="notifications-categories"> <ul> <li> <a href="#" id="unread-notifications"> <span class="title">unread notifications</span> <i class="fa fa-circle fa-fw"></i> <span class="count">4</span> </a> </li> <li> <a href="#" id="all-notifications" style="height: 60px; line-height: 60px; ">all notifications</a> </li> </ul> </div> <ul data-role="listview" class="notifications-list" data-inset="true"> </ul> </div> </div> <script src="js/pages/notifications-list-view.js"></script>
in notifications-list-view.js
have code :
$("#unread-notifications").addclass ($.mobile.activebtnclass); filllist (4) $("#unread-notifications").on ("click", function () { filllist (4); }); $("#all-notifications").on ("click", function () { filllist (10); }); function filllist (count) { var listitemclass = "listitem"; var content = ""; if (!$(this).hasclass ($.mobile.activebtnclass)) { (i = 0; < count; ++) { content += '<li id=' + listitemclass + '>'; content += '<div class="delete-button"><a href="#" class="ui-btn delete-btn">delete</a></div>'; content += '<a href="#" class="notification-item-a">'; content += '<div class="ui-li-thumb"></div>'; content += '<div class="ui-li-text">'; content += '<h3>credit elligibility</h3>'; content += '<p class="notification-core">'; content += 'we have recievede uhdccd uhc cdyucd cduhcd ucdhcd cduhcd ucdcd ucd cuhcd ucdcd ucdbcd ubc ahlan how doing it\'s not good'; content += 'we have recievede uhdccd uhc cdyucd cduhcd ucdhcd cduhcd ucdcd ucd cuhcd ucdcd ucdbcd ubc ahlan how doing it\'s not good'; content += 'we have recievede uhdccd uhc cdyucd cduhcd ucdhcd cduhcd ucdcd ucd cuhcd ucdcd ucdbcd ubc ahlan how doing it\'s not good'; content += 'we have recievede uhdccd uhc cdyucd cduhcd ucdhcd cduhcd ucdcd ucd cuhcd ucdcd ucdbcd ubc ahlan how doing it\'s not good'; content += 'we have recievede uhdccd uhc cdyucd cduhcd ucdhcd cduhcd ucdcd ucd cuhcd ucdcd ucdbcd ubc ahlan how doing it\'s not good'; content += '</p>'; content += '</div>'; content += '</a>'; content += '</li>'; listitemclass = "listitem" + i; } $(".notifications-list").html (content); $(".notifications-list").trigger ("chosen:updated"); } }
however css / js loaded not applied.
how can create css style , js code applied dynamically added html content ?
thank you.
jqm doesn't apply styles (enhance) dynamically added elements, enhancement method should called based on widget used.
the problem you're calling filllist()
before page initialized, maybe you're using .ready()
. should hear jqm pagecontainer events run functions.
also, have understand jqm starts enhancing widgets during pagebeforecreate
event; when enhancement done, pagecreate
event fired. if add together elements dynamically during pagebeforecreate
don't need phone call enhancement method, however, on pagecreate
need manually enhance dynamic elements, e.g. .listview("refresh")
.
in filllist()
need $(".notifications-list").html(content);
when it's called during pagebeforecreate
.
$(document).on("pagebeforecreate", "#pageid", function () { filllist(20); });
in filllist()
need add together enhancement $(".notifications-list").html(content).listview("refresh")
.
$(document).on("pagecreate", "#pageid", function () { filllist(20); });
when want phone call filllist()
after page created , shown, need determine whether listview nowadays in dom , created.
.listview()
create after appending dynamically existed listview: utilize .listview("refresh")
apply styles new elements jquery css jquery-mobile
Comments
Post a Comment