i have following jquery/javascript code. adds several elements existing <div>
. works fine except i'd text inserted after first image.
does jquery provider simple syntax add child <img>
element before inner text? know can create elements separately i'd keep expressions simple possible.
var div = document.getelementbyid("div"); var attachmentdiv = $('<div />', { 'class': 'attachment' }); attachmentdiv.append($('<a />', { href: '#', title: 'download attachment', text: 'filename.ext' }) .append($('<img />', { src: 'https://cdn0.iconfinder.com/data/icons/typicons-2/24/spanner-128.png', 'class': 'attachmenticon', alt: 'file attachment' }))); attachmentdiv.append($('<a />', { href: '#', title: 'delete attachment', 'data-id': '000' }) .append($('<img />', { src: 'https://cdn0.iconfinder.com/data/icons/typicons-2/24/spanner-128.png', 'class': 'attachmentdeleteicon', alt: 'delete attachment' }))); $(div).append(attachmentdiv);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="div"></div>
var div = document.getelementbyid("div"); var attachmentdiv = $('<div />', { 'class': 'attachment' }); attachmentdiv.append($('<a />', { href: '#', title: 'download attachment', text: 'filename.ext' }) .prepend($('<img />', { src: 'https://cdn0.iconfinder.com/data/icons/typicons-2/24/spanner-128.png', 'class': 'attachmenticon', alt: 'file attachment' }))); attachmentdiv.append($('<a />', { href: '#', title: 'delete attachment', 'data-id': '000' }) .append($('<img />', { src: 'https://cdn0.iconfinder.com/data/icons/typicons-2/24/spanner-128.png', 'class': 'attachmentdeleteicon', alt: 'delete attachment' }))); $(div).append(attachmentdiv);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="div"></div>
Comments
Post a Comment