Home>

there is some list but it doesn't matter

<
UL >
  ≪
Li >
≪
B >
TEXT1 <
/b >
≪
/Li >
  ≪
Li >
≪
B >
TEXT2 <
/b >
≪
/Li >
  ≪
Li >
≪
B >
Text3 <
/b >
≪
/Li >
  ≪
Li >
≪
B >
Text4 <
/b >
≪
/Li >
≪
/ul >

I processed this code

$ (document) .on ('Click', 'UL Li', Function () {
Alert ($ (this) .html ());
});

Naturally, crashes ≪ B > TEXTN < /b > when clicking. how to do what would fly out only TextN. ??? I have tried

$ (this). $ ('B'). HTML ()

did not work
And so I tried

$ (this 'b'). HTML ()

Also without an answer gives an error

Link to jsfiddle

p.s. in place 'ul li' Do not offer 'ul li b' Since I have every LI It is a large area and an event should work on it.

Optional option

  • Answer # 1
    1. Try

      $ (this) .children ('b'). HTML ();

    2. Try

      $ (this) .text ();

    Both options work. Thank you

    igolka972021-05-22 18:41:51

    Naturally. I wrote try so that you choose the optimal. There is another third option: $ (this) .Children ('B'). Text (); The difference between all three options is that it will be withdrawn.

    • went Sasha software Highway
    first displays HTML from all fatty inscriptions in this element. Sasha Highway The second displays all text from the list item, even if it is not framed by tags. Sasha passed on the highway. The third displays the text from the fat inscriptions of the list item. Sasha Highway

    knes2021-05-22 18:41:51