conan
conan

Reputation: 1337

How can I make a comma disappear in jquery?

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">'+',');

Upvotes: 0

Views: 82

Answers (2)

Lumi Lu
Lumi Lu

Reputation: 3305

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());

Upvotes: 1

guest271314
guest271314

Reputation: 1

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>

Upvotes: 3

Related Questions