JQuery Syntax error, unrecognized expression :,

I am trying to just add a comma after each item in the list.

$('#tag_cloud-2 div.tagcloud a').each(function(){
  console.log($(this));
  $(", ").after($(this));
});

The console spits out tags, so I know that they find them. I tried insertAfter too, but no luck. These seams like this should be such a simple thing! Thank you for pointing out that I am missing.

+5
source share
2 answers

$(', ') considered as a selector (invalid) because it cannot create node text with a string.

But

$("<span>, </span>").after($(this)); will work due to valid markup.

Try:

$(this).after(', ');

OR

$(this).append(', ');

OR

$(this).text(function(i, oldText) {
  return oldText + ', ';
})
+5
source

jQuery $ () does not work like that. Calling it in a line without markup does not create the node text containing this line.

, $(this), after(), :

$(this).after(", ");

after() node, .

+1

All Articles