Skip to main content
October 21, 2011
Question

How to select previous paragraph?

  • October 21, 2011
  • 1 reply
  • 1768 views

Hi All,

I have selected my needed paragraph.

var cur_sel = app.selection[0].paragraphs;           Then How to select previous paragraph? pls suggest.

Indesign cs5 using javascript.

This topic has been closed for replies.

1 reply

csm_phil
Legend
October 21, 2011

Hi Kan,

Please try the below JS code.

This is working in the previous paragraphs if present the contents will be alert.

var myPreviousPara = app.selection[0].parentTextFrames[0].paragraphs.previousItem(app.selection[0].paragraphs[-1]);

alert(myPreviousPara.contents);

thx

csm_phil

Harbs.
Legend
October 23, 2011

It's much more efficient to do something like this:

function getPreviousPara(text){

  return text.parent.characters.item(text.paragraphs[0].index-1).paragraphs[0];

}

alert(getPreviousPara(app.selection[0]).contents);