Jquery - Modify a string into a span without remplacing everything -
i have following code , try modify 'delivered' string @ beginning of span. end remplacing content of span if use text() method.
i tried:
$('#delivered-on').parent().text(' delivered on: '); $('span.wizard-filter-delivery-date').not('#delivered-on,.deliverydays-container').text(' delivered on: ');
do have idea how that? best, nicolas
<span class="wizard-filter-delivery-date col-sm-12"> delivered <span id="delivered-on"> <div data-reactroot="" class="deliverydays-container"> <div class="deliverydays-no-touch-dropdown-container"> <div class="select select--single is-searchable has-value"> <div class="select-control"> <div class="select-value"><span class="select-value-label">friday, 13th may</span></div> <div class="select-input" style="display: inline-block;"> <input style="width: 5px; box-sizing: content-box;"> <div style="position: absolute; visibility: hidden; height: 0px; width: 0px; overflow: scroll; white-space: pre; font-size: 21px; font-family: lato, helvetica, sans-serif; font-weight: normal; font-style: normal; letter-spacing: normal;"></div> </div> <span class="select-arrow-zone"><span class="select-arrow"></span></span> </div> </div> </div> <div class="deliverydays-touch-dropdown-container"> <select class="deliverydays-select"> <option value="484">friday, 13th may</option> <option value="610">saturday, 14th may</option> <option value="725">monday, 16th may</option> <option value="487">wednesday, 18th may</option> <option value="488">friday, 20th may</option> <option value="611">saturday, 21st may</option> </select> </div> </div> </span> </span>
get text node , replace new content
$('.wizard-filter-delivery-date') .contents() // child nodes .eq(0) // first element, text node replaced .replacewith(' delivered on: '); // replace text
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <span class="wizard-filter-delivery-date col-sm-12"> delivered <span id="delivered-on"><div data-reactroot="" class="deliverydays-container"><div class="deliverydays-no-touch-dropdown-container"><div class="select select--single is-searchable has-value"><div class="select-control"><div class="select-value"><span class="select-value-label">friday, 13th may</span> </div> <div class="select-input" style="display: inline-block;"> <input style="width: 5px; box-sizing: content-box;"> <div style="position: absolute; visibility: hidden; height: 0px; width: 0px; overflow: scroll; white-space: pre; font-size: 21px; font-family: lato, helvetica, sans-serif; font-weight: normal; font-style: normal; letter-spacing: normal;"></div> </div><span class="select-arrow-zone"><span class="select-arrow"></span></span> </div> </div> </div> <div class="deliverydays-touch-dropdown-container"> <select class="deliverydays-select"> <option value="484">friday, 13th may</option> <option value="610">saturday, 14th may</option> <option value="725">monday, 16th may</option> <option value="487">wednesday, 18th may</option> <option value="488">friday, 20th may</option> <option value="611">saturday, 21st may</option> </select> </div> </div> </span> </span>
pure javascript method
document.getelementsbyclassname('wizard-filter-delivery-date')[0] // element class name .childnodes[0] // text node children nodes .textcontent = ' delivered on: '; // replace text
<span class="wizard-filter-delivery-date col-sm-12"> delivered <span id="delivered-on"><div data-reactroot="" class="deliverydays-container"><div class="deliverydays-no-touch-dropdown-container"><div class="select select--single is-searchable has-value"><div class="select-control"><div class="select-value"><span class="select-value-label">friday, 13th may</span> </div> <div class="select-input" style="display: inline-block;"> <input style="width: 5px; box-sizing: content-box;"> <div style="position: absolute; visibility: hidden; height: 0px; width: 0px; overflow: scroll; white-space: pre; font-size: 21px; font-family: lato, helvetica, sans-serif; font-weight: normal; font-style: normal; letter-spacing: normal;"></div> </div><span class="select-arrow-zone"><span class="select-arrow"></span></span> </div> </div> </div> <div class="deliverydays-touch-dropdown-container"> <select class="deliverydays-select"> <option value="484">friday, 13th may</option> <option value="610">saturday, 14th may</option> <option value="725">monday, 16th may</option> <option value="487">wednesday, 18th may</option> <option value="488">friday, 20th may</option> <option value="611">saturday, 21st may</option> </select> </div> </div> </span> </span>
Comments
Post a Comment