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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -