getting the first line of text in an element jquery











up vote
9
down vote

favorite












I have an example element like this:



<div id="element">
Blah blah blah.
<div>Header</div>
...
</div>


it can also look like this:



<div id="element">
<span>Blah blah blah.</span>
<h4>Header</h4>
...
</div>


I want to get the first line (defining line loosely) (Blah blah blah.) of text inside the element. It might be wrapped inside a child element or just be naked textnode. How do I do that? Thanks.










share|improve this question




























    up vote
    9
    down vote

    favorite












    I have an example element like this:



    <div id="element">
    Blah blah blah.
    <div>Header</div>
    ...
    </div>


    it can also look like this:



    <div id="element">
    <span>Blah blah blah.</span>
    <h4>Header</h4>
    ...
    </div>


    I want to get the first line (defining line loosely) (Blah blah blah.) of text inside the element. It might be wrapped inside a child element or just be naked textnode. How do I do that? Thanks.










    share|improve this question


























      up vote
      9
      down vote

      favorite









      up vote
      9
      down vote

      favorite











      I have an example element like this:



      <div id="element">
      Blah blah blah.
      <div>Header</div>
      ...
      </div>


      it can also look like this:



      <div id="element">
      <span>Blah blah blah.</span>
      <h4>Header</h4>
      ...
      </div>


      I want to get the first line (defining line loosely) (Blah blah blah.) of text inside the element. It might be wrapped inside a child element or just be naked textnode. How do I do that? Thanks.










      share|improve this question















      I have an example element like this:



      <div id="element">
      Blah blah blah.
      <div>Header</div>
      ...
      </div>


      it can also look like this:



      <div id="element">
      <span>Blah blah blah.</span>
      <h4>Header</h4>
      ...
      </div>


      I want to get the first line (defining line loosely) (Blah blah blah.) of text inside the element. It might be wrapped inside a child element or just be naked textnode. How do I do that? Thanks.







      javascript jquery html






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 11 '11 at 20:34

























      asked Sep 11 '11 at 20:27









      Harry

      17.1k53139223




      17.1k53139223
























          5 Answers
          5






          active

          oldest

          votes

















          up vote
          16
          down vote



          accepted










          Use the contents()[docs] method to get all children, including text nodes, filter out any empty (or whitespace only) nodes, then grab the first of the set.



          var first_line = $("#element")
          .contents()
          .filter(function() {
          return !!$.trim( this.innerHTML || this.data );
          })
          .first();


          text node: http://jsfiddle.net/Yftnh/



          element: http://jsfiddle.net/Yftnh/1/






          share|improve this answer

















          • 1




            Hi can you explain why you do return !!? What is !!?
            – Harry
            Sep 11 '11 at 20:53






          • 1




            It converts to the value's boolean equivalent. After trimming, if .innerHTML or .data returns an empty string, !! will convert it to boolean false, because an empty string is considered a "falsey" value. Any non-empty string will result in true. stackoverflow.com/questions/4686583/…
            – user113716
            Sep 11 '11 at 20:54








          • 2




            +1 from me, but the performance-wary might want to consider using $.each() rather than filter(). It's a bit late in the day for me, but an example of this is jsfiddle.net/AndyE/Yftnh/3 (ignore revision 2, I'm half asleep here!)
            – Andy E
            Sep 11 '11 at 20:56






          • 2




            @Andy E: Nice one. Great use of the comma operator too. @Harry: It just lets you stop the loop once you've found a non-empty node. With .filter() you have to let the loop run for each element that .contents() returns.
            – user113716
            Sep 11 '11 at 20:58








          • 1




            @Andy E: For fun, here's one sans comma return !$.trim((first_line = this).innerHTML||this.data); :)
            – user113716
            Sep 11 '11 at 21:03


















          up vote
          2
          down vote













          Here is idea for you. Of course if there is h4 element before line you want to get:



          var content = $('#element').html();
          var arr = content.split('<h4>');
          console.log(arr[0]);





          share|improve this answer





















          • no h4 guaranteed, it's just an example
            – Harry
            Sep 11 '11 at 20:36


















          up vote
          2
          down vote













          var myElement = $("#element");
          while(myElement.children().length > 0)
          {
          myElement = myElement.children().first();
          }
          var firstText = myElement.text();


          Assuming that the text is correctly wrapped inside an element, of course. You might check whether there's text before the first element:



          /s*</.test(myElement.html())





          share|improve this answer























          • Doesn't work for the first case I believe, that'll match the Header rather than the blah blah blah (maybe should've picked better example text lol)
            – Harry
            Sep 11 '11 at 20:36












          • If you get <div id="element"><span></span>mytext</div> it gets pretty difficult. You need something recursively traveling through the DOM i guess. How bulletproof does it have to be?
            – Maximilian Hils
            Sep 11 '11 at 20:42


















          up vote
          0
          down vote













          first get the content of the element



          var content = $('#element').html();


          then split the text into an array using line break



          tmp = content.split("n");


          the first part of the array is the first line of the element



          var firstLine = tmp[0];





          share|improve this answer

















          • 1




            I first thought, what linebreak, but I see in Fx at least there is. It is however dangerous to rely on. Here is the first line: alert($("#element").text().split(/n/)[1]) the [0]th is an empty string... jsfiddle.net/mplungjan/QquSp
            – mplungjan
            Sep 11 '11 at 20:33












          • there's no linebreak
            – Harry
            Sep 11 '11 at 20:33


















          up vote
          0
          down vote













          the counter starts at 1



          myElement.text().split('n')[1]





          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7381012%2fgetting-the-first-line-of-text-in-an-element-jquery%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            5 Answers
            5






            active

            oldest

            votes








            5 Answers
            5






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            16
            down vote



            accepted










            Use the contents()[docs] method to get all children, including text nodes, filter out any empty (or whitespace only) nodes, then grab the first of the set.



            var first_line = $("#element")
            .contents()
            .filter(function() {
            return !!$.trim( this.innerHTML || this.data );
            })
            .first();


            text node: http://jsfiddle.net/Yftnh/



            element: http://jsfiddle.net/Yftnh/1/






            share|improve this answer

















            • 1




              Hi can you explain why you do return !!? What is !!?
              – Harry
              Sep 11 '11 at 20:53






            • 1




              It converts to the value's boolean equivalent. After trimming, if .innerHTML or .data returns an empty string, !! will convert it to boolean false, because an empty string is considered a "falsey" value. Any non-empty string will result in true. stackoverflow.com/questions/4686583/…
              – user113716
              Sep 11 '11 at 20:54








            • 2




              +1 from me, but the performance-wary might want to consider using $.each() rather than filter(). It's a bit late in the day for me, but an example of this is jsfiddle.net/AndyE/Yftnh/3 (ignore revision 2, I'm half asleep here!)
              – Andy E
              Sep 11 '11 at 20:56






            • 2




              @Andy E: Nice one. Great use of the comma operator too. @Harry: It just lets you stop the loop once you've found a non-empty node. With .filter() you have to let the loop run for each element that .contents() returns.
              – user113716
              Sep 11 '11 at 20:58








            • 1




              @Andy E: For fun, here's one sans comma return !$.trim((first_line = this).innerHTML||this.data); :)
              – user113716
              Sep 11 '11 at 21:03















            up vote
            16
            down vote



            accepted










            Use the contents()[docs] method to get all children, including text nodes, filter out any empty (or whitespace only) nodes, then grab the first of the set.



            var first_line = $("#element")
            .contents()
            .filter(function() {
            return !!$.trim( this.innerHTML || this.data );
            })
            .first();


            text node: http://jsfiddle.net/Yftnh/



            element: http://jsfiddle.net/Yftnh/1/






            share|improve this answer

















            • 1




              Hi can you explain why you do return !!? What is !!?
              – Harry
              Sep 11 '11 at 20:53






            • 1




              It converts to the value's boolean equivalent. After trimming, if .innerHTML or .data returns an empty string, !! will convert it to boolean false, because an empty string is considered a "falsey" value. Any non-empty string will result in true. stackoverflow.com/questions/4686583/…
              – user113716
              Sep 11 '11 at 20:54








            • 2




              +1 from me, but the performance-wary might want to consider using $.each() rather than filter(). It's a bit late in the day for me, but an example of this is jsfiddle.net/AndyE/Yftnh/3 (ignore revision 2, I'm half asleep here!)
              – Andy E
              Sep 11 '11 at 20:56






            • 2




              @Andy E: Nice one. Great use of the comma operator too. @Harry: It just lets you stop the loop once you've found a non-empty node. With .filter() you have to let the loop run for each element that .contents() returns.
              – user113716
              Sep 11 '11 at 20:58








            • 1




              @Andy E: For fun, here's one sans comma return !$.trim((first_line = this).innerHTML||this.data); :)
              – user113716
              Sep 11 '11 at 21:03













            up vote
            16
            down vote



            accepted







            up vote
            16
            down vote



            accepted






            Use the contents()[docs] method to get all children, including text nodes, filter out any empty (or whitespace only) nodes, then grab the first of the set.



            var first_line = $("#element")
            .contents()
            .filter(function() {
            return !!$.trim( this.innerHTML || this.data );
            })
            .first();


            text node: http://jsfiddle.net/Yftnh/



            element: http://jsfiddle.net/Yftnh/1/






            share|improve this answer












            Use the contents()[docs] method to get all children, including text nodes, filter out any empty (or whitespace only) nodes, then grab the first of the set.



            var first_line = $("#element")
            .contents()
            .filter(function() {
            return !!$.trim( this.innerHTML || this.data );
            })
            .first();


            text node: http://jsfiddle.net/Yftnh/



            element: http://jsfiddle.net/Yftnh/1/







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Sep 11 '11 at 20:41









            user113716

            257k55399416




            257k55399416








            • 1




              Hi can you explain why you do return !!? What is !!?
              – Harry
              Sep 11 '11 at 20:53






            • 1




              It converts to the value's boolean equivalent. After trimming, if .innerHTML or .data returns an empty string, !! will convert it to boolean false, because an empty string is considered a "falsey" value. Any non-empty string will result in true. stackoverflow.com/questions/4686583/…
              – user113716
              Sep 11 '11 at 20:54








            • 2




              +1 from me, but the performance-wary might want to consider using $.each() rather than filter(). It's a bit late in the day for me, but an example of this is jsfiddle.net/AndyE/Yftnh/3 (ignore revision 2, I'm half asleep here!)
              – Andy E
              Sep 11 '11 at 20:56






            • 2




              @Andy E: Nice one. Great use of the comma operator too. @Harry: It just lets you stop the loop once you've found a non-empty node. With .filter() you have to let the loop run for each element that .contents() returns.
              – user113716
              Sep 11 '11 at 20:58








            • 1




              @Andy E: For fun, here's one sans comma return !$.trim((first_line = this).innerHTML||this.data); :)
              – user113716
              Sep 11 '11 at 21:03














            • 1




              Hi can you explain why you do return !!? What is !!?
              – Harry
              Sep 11 '11 at 20:53






            • 1




              It converts to the value's boolean equivalent. After trimming, if .innerHTML or .data returns an empty string, !! will convert it to boolean false, because an empty string is considered a "falsey" value. Any non-empty string will result in true. stackoverflow.com/questions/4686583/…
              – user113716
              Sep 11 '11 at 20:54








            • 2




              +1 from me, but the performance-wary might want to consider using $.each() rather than filter(). It's a bit late in the day for me, but an example of this is jsfiddle.net/AndyE/Yftnh/3 (ignore revision 2, I'm half asleep here!)
              – Andy E
              Sep 11 '11 at 20:56






            • 2




              @Andy E: Nice one. Great use of the comma operator too. @Harry: It just lets you stop the loop once you've found a non-empty node. With .filter() you have to let the loop run for each element that .contents() returns.
              – user113716
              Sep 11 '11 at 20:58








            • 1




              @Andy E: For fun, here's one sans comma return !$.trim((first_line = this).innerHTML||this.data); :)
              – user113716
              Sep 11 '11 at 21:03








            1




            1




            Hi can you explain why you do return !!? What is !!?
            – Harry
            Sep 11 '11 at 20:53




            Hi can you explain why you do return !!? What is !!?
            – Harry
            Sep 11 '11 at 20:53




            1




            1




            It converts to the value's boolean equivalent. After trimming, if .innerHTML or .data returns an empty string, !! will convert it to boolean false, because an empty string is considered a "falsey" value. Any non-empty string will result in true. stackoverflow.com/questions/4686583/…
            – user113716
            Sep 11 '11 at 20:54






            It converts to the value's boolean equivalent. After trimming, if .innerHTML or .data returns an empty string, !! will convert it to boolean false, because an empty string is considered a "falsey" value. Any non-empty string will result in true. stackoverflow.com/questions/4686583/…
            – user113716
            Sep 11 '11 at 20:54






            2




            2




            +1 from me, but the performance-wary might want to consider using $.each() rather than filter(). It's a bit late in the day for me, but an example of this is jsfiddle.net/AndyE/Yftnh/3 (ignore revision 2, I'm half asleep here!)
            – Andy E
            Sep 11 '11 at 20:56




            +1 from me, but the performance-wary might want to consider using $.each() rather than filter(). It's a bit late in the day for me, but an example of this is jsfiddle.net/AndyE/Yftnh/3 (ignore revision 2, I'm half asleep here!)
            – Andy E
            Sep 11 '11 at 20:56




            2




            2




            @Andy E: Nice one. Great use of the comma operator too. @Harry: It just lets you stop the loop once you've found a non-empty node. With .filter() you have to let the loop run for each element that .contents() returns.
            – user113716
            Sep 11 '11 at 20:58






            @Andy E: Nice one. Great use of the comma operator too. @Harry: It just lets you stop the loop once you've found a non-empty node. With .filter() you have to let the loop run for each element that .contents() returns.
            – user113716
            Sep 11 '11 at 20:58






            1




            1




            @Andy E: For fun, here's one sans comma return !$.trim((first_line = this).innerHTML||this.data); :)
            – user113716
            Sep 11 '11 at 21:03




            @Andy E: For fun, here's one sans comma return !$.trim((first_line = this).innerHTML||this.data); :)
            – user113716
            Sep 11 '11 at 21:03












            up vote
            2
            down vote













            Here is idea for you. Of course if there is h4 element before line you want to get:



            var content = $('#element').html();
            var arr = content.split('<h4>');
            console.log(arr[0]);





            share|improve this answer





















            • no h4 guaranteed, it's just an example
              – Harry
              Sep 11 '11 at 20:36















            up vote
            2
            down vote













            Here is idea for you. Of course if there is h4 element before line you want to get:



            var content = $('#element').html();
            var arr = content.split('<h4>');
            console.log(arr[0]);





            share|improve this answer





















            • no h4 guaranteed, it's just an example
              – Harry
              Sep 11 '11 at 20:36













            up vote
            2
            down vote










            up vote
            2
            down vote









            Here is idea for you. Of course if there is h4 element before line you want to get:



            var content = $('#element').html();
            var arr = content.split('<h4>');
            console.log(arr[0]);





            share|improve this answer












            Here is idea for you. Of course if there is h4 element before line you want to get:



            var content = $('#element').html();
            var arr = content.split('<h4>');
            console.log(arr[0]);






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Sep 11 '11 at 20:33









            simoncereska

            2,6491223




            2,6491223












            • no h4 guaranteed, it's just an example
              – Harry
              Sep 11 '11 at 20:36


















            • no h4 guaranteed, it's just an example
              – Harry
              Sep 11 '11 at 20:36
















            no h4 guaranteed, it's just an example
            – Harry
            Sep 11 '11 at 20:36




            no h4 guaranteed, it's just an example
            – Harry
            Sep 11 '11 at 20:36










            up vote
            2
            down vote













            var myElement = $("#element");
            while(myElement.children().length > 0)
            {
            myElement = myElement.children().first();
            }
            var firstText = myElement.text();


            Assuming that the text is correctly wrapped inside an element, of course. You might check whether there's text before the first element:



            /s*</.test(myElement.html())





            share|improve this answer























            • Doesn't work for the first case I believe, that'll match the Header rather than the blah blah blah (maybe should've picked better example text lol)
              – Harry
              Sep 11 '11 at 20:36












            • If you get <div id="element"><span></span>mytext</div> it gets pretty difficult. You need something recursively traveling through the DOM i guess. How bulletproof does it have to be?
              – Maximilian Hils
              Sep 11 '11 at 20:42















            up vote
            2
            down vote













            var myElement = $("#element");
            while(myElement.children().length > 0)
            {
            myElement = myElement.children().first();
            }
            var firstText = myElement.text();


            Assuming that the text is correctly wrapped inside an element, of course. You might check whether there's text before the first element:



            /s*</.test(myElement.html())





            share|improve this answer























            • Doesn't work for the first case I believe, that'll match the Header rather than the blah blah blah (maybe should've picked better example text lol)
              – Harry
              Sep 11 '11 at 20:36












            • If you get <div id="element"><span></span>mytext</div> it gets pretty difficult. You need something recursively traveling through the DOM i guess. How bulletproof does it have to be?
              – Maximilian Hils
              Sep 11 '11 at 20:42













            up vote
            2
            down vote










            up vote
            2
            down vote









            var myElement = $("#element");
            while(myElement.children().length > 0)
            {
            myElement = myElement.children().first();
            }
            var firstText = myElement.text();


            Assuming that the text is correctly wrapped inside an element, of course. You might check whether there's text before the first element:



            /s*</.test(myElement.html())





            share|improve this answer














            var myElement = $("#element");
            while(myElement.children().length > 0)
            {
            myElement = myElement.children().first();
            }
            var firstText = myElement.text();


            Assuming that the text is correctly wrapped inside an element, of course. You might check whether there's text before the first element:



            /s*</.test(myElement.html())






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Sep 11 '11 at 20:40

























            answered Sep 11 '11 at 20:34









            Maximilian Hils

            3,80421331




            3,80421331












            • Doesn't work for the first case I believe, that'll match the Header rather than the blah blah blah (maybe should've picked better example text lol)
              – Harry
              Sep 11 '11 at 20:36












            • If you get <div id="element"><span></span>mytext</div> it gets pretty difficult. You need something recursively traveling through the DOM i guess. How bulletproof does it have to be?
              – Maximilian Hils
              Sep 11 '11 at 20:42


















            • Doesn't work for the first case I believe, that'll match the Header rather than the blah blah blah (maybe should've picked better example text lol)
              – Harry
              Sep 11 '11 at 20:36












            • If you get <div id="element"><span></span>mytext</div> it gets pretty difficult. You need something recursively traveling through the DOM i guess. How bulletproof does it have to be?
              – Maximilian Hils
              Sep 11 '11 at 20:42
















            Doesn't work for the first case I believe, that'll match the Header rather than the blah blah blah (maybe should've picked better example text lol)
            – Harry
            Sep 11 '11 at 20:36






            Doesn't work for the first case I believe, that'll match the Header rather than the blah blah blah (maybe should've picked better example text lol)
            – Harry
            Sep 11 '11 at 20:36














            If you get <div id="element"><span></span>mytext</div> it gets pretty difficult. You need something recursively traveling through the DOM i guess. How bulletproof does it have to be?
            – Maximilian Hils
            Sep 11 '11 at 20:42




            If you get <div id="element"><span></span>mytext</div> it gets pretty difficult. You need something recursively traveling through the DOM i guess. How bulletproof does it have to be?
            – Maximilian Hils
            Sep 11 '11 at 20:42










            up vote
            0
            down vote













            first get the content of the element



            var content = $('#element').html();


            then split the text into an array using line break



            tmp = content.split("n");


            the first part of the array is the first line of the element



            var firstLine = tmp[0];





            share|improve this answer

















            • 1




              I first thought, what linebreak, but I see in Fx at least there is. It is however dangerous to rely on. Here is the first line: alert($("#element").text().split(/n/)[1]) the [0]th is an empty string... jsfiddle.net/mplungjan/QquSp
              – mplungjan
              Sep 11 '11 at 20:33












            • there's no linebreak
              – Harry
              Sep 11 '11 at 20:33















            up vote
            0
            down vote













            first get the content of the element



            var content = $('#element').html();


            then split the text into an array using line break



            tmp = content.split("n");


            the first part of the array is the first line of the element



            var firstLine = tmp[0];





            share|improve this answer

















            • 1




              I first thought, what linebreak, but I see in Fx at least there is. It is however dangerous to rely on. Here is the first line: alert($("#element").text().split(/n/)[1]) the [0]th is an empty string... jsfiddle.net/mplungjan/QquSp
              – mplungjan
              Sep 11 '11 at 20:33












            • there's no linebreak
              – Harry
              Sep 11 '11 at 20:33













            up vote
            0
            down vote










            up vote
            0
            down vote









            first get the content of the element



            var content = $('#element').html();


            then split the text into an array using line break



            tmp = content.split("n");


            the first part of the array is the first line of the element



            var firstLine = tmp[0];





            share|improve this answer












            first get the content of the element



            var content = $('#element').html();


            then split the text into an array using line break



            tmp = content.split("n");


            the first part of the array is the first line of the element



            var firstLine = tmp[0];






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Sep 11 '11 at 20:33









            clem

            2,42211632




            2,42211632








            • 1




              I first thought, what linebreak, but I see in Fx at least there is. It is however dangerous to rely on. Here is the first line: alert($("#element").text().split(/n/)[1]) the [0]th is an empty string... jsfiddle.net/mplungjan/QquSp
              – mplungjan
              Sep 11 '11 at 20:33












            • there's no linebreak
              – Harry
              Sep 11 '11 at 20:33














            • 1




              I first thought, what linebreak, but I see in Fx at least there is. It is however dangerous to rely on. Here is the first line: alert($("#element").text().split(/n/)[1]) the [0]th is an empty string... jsfiddle.net/mplungjan/QquSp
              – mplungjan
              Sep 11 '11 at 20:33












            • there's no linebreak
              – Harry
              Sep 11 '11 at 20:33








            1




            1




            I first thought, what linebreak, but I see in Fx at least there is. It is however dangerous to rely on. Here is the first line: alert($("#element").text().split(/n/)[1]) the [0]th is an empty string... jsfiddle.net/mplungjan/QquSp
            – mplungjan
            Sep 11 '11 at 20:33






            I first thought, what linebreak, but I see in Fx at least there is. It is however dangerous to rely on. Here is the first line: alert($("#element").text().split(/n/)[1]) the [0]th is an empty string... jsfiddle.net/mplungjan/QquSp
            – mplungjan
            Sep 11 '11 at 20:33














            there's no linebreak
            – Harry
            Sep 11 '11 at 20:33




            there's no linebreak
            – Harry
            Sep 11 '11 at 20:33










            up vote
            0
            down vote













            the counter starts at 1



            myElement.text().split('n')[1]





            share|improve this answer

























              up vote
              0
              down vote













              the counter starts at 1



              myElement.text().split('n')[1]





              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                the counter starts at 1



                myElement.text().split('n')[1]





                share|improve this answer












                the counter starts at 1



                myElement.text().split('n')[1]






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 8 at 8:46









                Mo D Genesis

                14010




                14010






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7381012%2fgetting-the-first-line-of-text-in-an-element-jquery%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Academy of Television Arts & Sciences

                    L'Équipe

                    1995 France bombings