In my situation, I need to append ',' to separate each img in order to implode(), but I don't want to show the comma between each img, how can I css the visibility of the comma. By the way, I cannot use space +" ", why, because I have text and space between them, if I use space, then it will broke those word too.
imag=$('.result_tag:last').append('<img src="remove_sign.png">'+',');
Try
.result .tag:last-child:after {
content:",";
}
var imag = $('.result .tag:last') .append('<img width=50px height=50px style=background-color:sienna; />');
.result .tag:last-child:after { content:","; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="result"> <div class="tag">a</div> <div class="tag">b</div> </div>
I am assuming you will add multiple img tags in a loop. If it is true, I would like to create an array and push the each img tag string into the array and then using join() to a string and appending this string to the $('.result_tag:last') selector.
Try to something like this,
var arr =[];
var length=5;
for(var i <length; i++){
arr.push('<img src="remove_sign.png">');
}
imag=$('.result_tag:last').append(arr.join());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.