Using JQuery to get text of a div that's a child of a header to replace a different header
- by Stevie Jenowski
Hello all,
I'm trying to get the text contents of a .div('.child#') child of my event.target('h6.class'), and replace my other headers('h1.replacHeader#') using this script below...
$('h6.class').click(function(event) {
var $target = $(event.target);
$('.replaceHeader1').replaceWith("<h1 class='replaceHeader1'>" + $target.children(".child1").text() + "</h1>");
$('.replaceHeader2').replaceWith("<h1 class='replaceHeader2'>" + $target.children(".child2").text() + "</h1>");
});
});
I've noticed that .text() apparently doesn't apply to an event.target... So how could I go about achieving this?