How to display only the first word of the H2 header with JavaScript or CSS

advertisements

I Just wanted to know, is there any way though which we can display only First Word from h2 Heading.

For Example:

In the source code it should look like this

<h2> Stackoverflow is an Ideal Place</h2>

However, on live website it should look like this

Stackoverflow

Basically, we want to display the FIRST WORD from the whole heading. However, Search engine should read the complete title.


Try this way

$(document).ready(function(){
    var ac = $("#ac").text().split(' ');
    $("#ac").text(ac[0])
})