Add and remove image

Description

The following code shows how to add and remove image.

Example


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.8.3.js'></script>
<script type="text/javascript"
  src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.js"></script>
<link rel="stylesheet" type="text/css"
  href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.css">
<style type='text/css'>
li {<!--from w ww.j  av a2 s.  c o  m-->
  cursor: pointer;
}

.icon {
  position: absolute;
  right: 10px;
}
</style>
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
$('li').click(function(){
    if($(this).find('img').length > 0) {
        console.log('remove img');
        $(this).find('img').remove();
    } else {
        console.log('add img');
        $(this).append('<img src="http://placehold.it/300x30" class="icon"/>');
    }
});
});//]]>  
</script>
</head>
<body>
  <ul data-role="listview" data-inset="true">
    <li>Line 1</li>
    <li>Line 2</li>
    <li>Line 3</li>
  </ul>
</body>
</html>

Click to view the demo





















Home »
  jQuery Mobile »
    Example »




Button
Button Event
Button Icon
Button Text
Checkbox
Collapsible
Date
Dialog
Event
Footer
Form
Header
Icon
Input
Layout
Listview
Listview Divider
Listview Item
Loader
mobile_settings
Navbar
Page
Page Event
Popup
Radio
Select
Slider
Switch
Textarea
Theme