snipt

Ctrl+h for KB shortcuts

JavaScript

bold the first word in a heading

1
2
3
4
5
6
//bold the first word in an element like a paragraph or heading
//bold the first word of the page title
	jQuery('h1.page-title').each(function(){
    		var boldMe = jQuery(this);
    		boldMe.html( boldMe.text().replace(/(^\w+|\s+\w+)/,'<strong>$1</strong>') );
  	});
https://snipt.net/embed/204c5fe48b87f7978cab3ab2e47af816/
/raw/204c5fe48b87f7978cab3ab2e47af816/
204c5fe48b87f7978cab3ab2e47af816
js
JavaScript
6
2019-06-23T11:49:34
True
False
False
/api/public/snipt/27850/
bold-the-first-word-in-a-heading
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1">//bold the first word in an element like a paragraph or heading</span> </span><span id="L-2"><a name="L-2"></a><span class="c1">//bold the first word of the page title</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">jQuery</span><span class="p">(</span><span class="s1">&#39;h1.page-title&#39;</span><span class="p">).</span><span class="nx">each</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span> </span><span id="L-4"><a name="L-4"></a> <span class="kd">var</span> <span class="nx">boldMe</span> <span class="o">=</span> <span class="nx">jQuery</span><span class="p">(</span><span class="k">this</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a> <span class="nx">boldMe</span><span class="p">.</span><span class="nx">html</span><span class="p">(</span> <span class="nx">boldMe</span><span class="p">.</span><span class="nx">text</span><span class="p">().</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/(^\w+|\s+\w+)/</span><span class="p">,</span><span class="s1">&#39;&lt;strong&gt;$1&lt;/strong&gt;&#39;</span><span class="p">)</span> <span class="p">);</span> </span><span id="L-6"><a name="L-6"></a> <span class="p">});</span> </span></pre></div> </td></tr></table>
"first word", bold, heading

Text only

CSS Heading Comment

/* =Heading
----------------------------------------------- */
https://snipt.net/embed/c309383a3c7fbe9dcd1ed47ae7399c0d/
/raw/c309383a3c7fbe9dcd1ed47ae7399c0d/
c309383a3c7fbe9dcd1ed47ae7399c0d
text
Text only
2
2019-06-26T08:59:15
True
False
False
/api/public/snipt/1733/
css-heading-comment
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>/* =Heading </span><span id="L-2"><a name="L-2"></a>----------------------------------------------- */ </span></pre></div> </td></tr></table>
comment, css, heading