Question

Given a block of text in a TEXT EDITOR (CKEDITOR), with paragraphs contained in PARAGRAPH tags, how can I do in JQUERY to extract only the first paragraph

Example:

blah blah blah blah blah

blah blah blah 123123blah blah

blah blah blah blah b1212lah

blah blah blah blaasdasdadsh blah

To Just:

blah blah blah blah blah

Thanks

Was it helpful?

Solution

You can use the :first selector:

$('p:first');

OTHER TIPS

Since CKeditor is in an iframe, you might need something along the lines of:

$("#cke_contents_editor1 iframe").contents().find('p:first').text()

to extract the text.

I don't know if CKEditor would affect this in any way, but with jQuery you should be able to use:

$("p:first").text();

To get the text in the first <p> element. If the paragraphs are wrapped by a <div> or another element with a specific ID, you can do:

$("#id-of-div p:first").text();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top