0

http://jsbin.com/uxepap/3/edit

Here is div with links inside. I'm trying to replace comma inside last <a> with point "."

This comma comes from numeral sort of the list, should be replaced with point.

The problem is, all links stored inside links var, not sure how to get the last one and then replace it.

Any thoughts?

4

2 に答える 2

2

使用するString.replace

var links = $('a');

var $last = links.filter(":last");

$last.html( $last.html().replace(",", "."));

http://jsbin.com/uxepap/5/edit

于 2012-05-27T14:32:23.203 に答える
2
links.eq(-1).html(function(index, value) {
  return value.replace(/,\s*$/, ".");
});

デモ: http://jsbin.com/uxepap/7/edit

于 2012-05-27T14:33:50.550 に答える