-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
  • 18,559
  • 34
  • 93
  • 168

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
  • 9