-2
var machine = $('h1').contents(':not(small, a)').text();
console.log(machine);

<h1>Title <small>subheading</small> <a href="#"></a></h1>

I am trying to get the text which is Title to display using the above jQuery but of course this console.logs a blank line. Basically excluding the small and a tags

jsFiddle

ngplayground
  • 20,365
  • 36
  • 94
  • 173

1 Answers1

1
var machine = $("h1")
.clone()    //clone the element
.children() //select all the children
.remove()   //remove all the children
.end()  //again go back to selected element
.text();

alert(machine);
monu
  • 370
  • 1
  • 10