Selected text and making bold apart from first word using jQuery -


i know simple still new jquery, i'm little unsure how approach. have found few solutions making first word bold not need.

i want make words bold other first word; possible?

i.e

buy product

to be

buy this product

i have example solution first word not sure how adjust.

$('.homepage-boxes .ty-banner__image-wrapper a').find('.ty-btn_ghost').html(function(i, h){     return h.replace(/\w+\s/, function(firstword){       return '<strong>' + firstword + '</strong>';     });   }); 

i have adjusted classes need , find class want make text <strong> excluding first word.

there few ways this. use regex / (.*)/ match first space followed every other character end of string sub match:

$('.homepage-boxes .ty-banner__image-wrapper a').find('.ty-btn_ghost').html(function(i, h){    return h.replace(/ (.*)/, " <strong>$1</strong>");  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  <!-- html structure improvised match selectors question's js -->  <div class="homepage-boxes">    <div class="ty-banner__image-wrapper">      <a><span class="ty-btn_ghost">buy product</span></a>    </div>    <div class="ty-banner__image-wrapper">      <a><span class="ty-btn_ghost">buy other product</span></a>    </div>    <div class="ty-banner__image-wrapper">      <a><span class="ty-btn_ghost">buy third product</span></a>    </div>  </div>

note using parentheses in regex allows refer matched bit using $1, can provide replacement string in second argument .replace() rather passing function.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -