javascript - How to get text of this element not the child -
i want hide text first text only, using (opacity:0) when mouse on topblock.
<div class="topblock"> first text <div class="block"> inner text </div> </div> but when use following jquery code getting child div text first text inner text
$(".topblock").on("mouseenter",function(){ console.log($(this).text()); $(this).css({"opacity":"0"}) }).on("mouseleave",function(){ });
to require without amending html structure exceptionally difficult need amend textnode holding first text value directly.
instead far simpler amend html wrap text in element, such span, , perform operations on element. try this:
<div class="topblock"> <span>first text</span> <div class="block"> inner text </div> </div> $(".topblock").on("hover",function(){ $(this).find('span').toggle(); });
Comments
Post a Comment