I want to format this date:
.
First I want to split the string at the first /
and have the res
Instead of using substring with a fixed index, you'd better use replace
:
$("#date").html(function(t){
return t.replace(/^([^\/]*\/)/, '$1
')
});
One advantage is that it would still work if the first /
is at a different position.
Another advantage of this construct is that it would be extensible to more than one elements, for example to all those implementing a class, just by changing the selector.
Demonstration (note that I had to select jQuery in the menu in the left part of jsfiddle's window)