jquery - Can I use a split in replace? -
i have html looks this:
<div id=lw> <div class=lw> <ul id=lwe> <li class=lwe> <div class=lwn> <span class=lwn0>jul 1 - sep 6 </span> i care "jul" part of contents of span. trying see span has "jul", replace "july".
i'm trying shave off " - sep 6" using split() on span class, , replacing old html text new. code:
var = $(".lwn0").text(); var rep = $(".lwn0").html().replace(a, a.split(' - ')[0]); $(".lwn0").html(rep); that's not working. i'm not sure why. is legal use split() inside of replace()?
you're using replace on html instead of text.
this should work:
var rep = a.replace(a, a.split(' - ')[0]);
Comments
Post a Comment