-1

I have the following code :

<ul id="rubrique_1" class="questionZone ui-sortable">
Rubrique par défaut
<li id="question_1" class="questionStyle">(Q) Matrice case a coché</li></ul>

How can I get the HTML "Rubrique par défaut" without all the HTML of the li div with jQuery? I don't want to put div for the text because I'm using sortable function on ul rubrique_1.

$('#rubrique_1").text()

gives me all the HTML.

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
  • 7
    Your html is invalid, the [allowed content](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ul) for a `ul` is basically just `li` (and a couple of other edge cases) It can't contain text outside of an `li`. Also, your jQuery has two different types of quotation marks wrapping the selector, so it won't run. – DBS Sep 15 '20 at 12:49
  • If you can change the html move `Rubrique par défaut` in the
  • and wrap it with with custom id. Then you can get it with $('#custom id").text()
  • – Karmidzhanov Sep 15 '20 at 12:58
  • 1
    Does this answer your question? [How do I select text nodes with jQuery?](https://stackoverflow.com/questions/298750/how-do-i-select-text-nodes-with-jquery) – Mark Baijens Sep 15 '20 at 13:01