I've this piece of markup. This piece has been loaded through ajax and appended inside a div.
Content of file user-bar.php
:
<div id="u-bar">
<ul id="u-nav" class="nav">
<li id="notifications-list" class="dropdown" data-time="" >
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="icon-comment"></i>
Notifications
<b class="caret"></b>
</a>
<ul class="dropdown-menu" >
<li><a href="#">Notification One</a></li>
<li><a href="#">Notification two</a></li>
<li class="divider"></li>
<li><a href="#">Show All Notifications</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="icon-user"></i>
Profile
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><a href="#">View Profile</a></li>
<li><a href="#">Settings</a></li>
</ul>
</li>
<li><a href="php/logout.php">Logout</a></li>
<div class="clear"></div>
</ul>
</div>
I've scripts.js
file as below which is included in the index.php
file as <script type="text/javascript" src="js/scripts.js"></script>
$(function(){
loadUserBar();
$('#notifications-list').live('click', function(){
console.log('Test');
$('#notifications-list .icon-comment').removeClass('new');
});
});
function loadUserBar(){
$('#user-area').load('php/user-bar.php', function(){
initBootstrapElems(); //Initializing All popover elements
});
}
index.php
file has the div#user-area
where the ajax returned markup is inserted.
After the whole page has been loaded, when I click on the list-item #notifications-list
, nothing happens. But when I typed in $('#notifications-list').click()
directly in the console, the log does appears and the removeClass
does occur.
What could be wrong here?