Skip to main content
Participant
Jun 10, 2025 9:23 AM UTC
Answered

Use of currentParagraph.paragraphStyle with JSX

Hi, I try to change the paragraph style of a text using this function in jsx : currentParagraph.paragraphStyle = styleToApply; 

 

the style exists and no error appears but nothin happend. Somebody know why? I made a lot of tests during hours but i can't find the issue!

 

Thanks in advance.

 

Ludovic Schmidt

CarlosCanto
CarlosCantoCorrect answer
Community Expert
Jun 10, 2025 4:07 PM UTC

The syntax you're using is incorrect. You have to supply the paragraph to the paragraph style.

 

var idoc = app.activeDocument;

var myPara = idoc.paragraphStyles["myPara"]; // paragraph style name

var para0 = selection[0].textRange.paragraphs[0]; // selected text frame first paragraph 

myPara.applyTo(para0, true); // apply paragraph style to supplied paragraph

4 replies

CarlosCanto
Community Expert
CarlosCantoCommunity ExpertCorrect answer
Community Expert
Jun 10, 2025 4:07 PM UTC

The syntax you're using is incorrect. You have to supply the paragraph to the paragraph style.

 

var idoc = app.activeDocument;

var myPara = idoc.paragraphStyles["myPara"]; // paragraph style name

var para0 = selection[0].textRange.paragraphs[0]; // selected text frame first paragraph 

myPara.applyTo(para0, true); // apply paragraph style to supplied paragraph
Translate
Participant
Jun 11, 2025 5:52 AM UTC

Thanks for your help. What about character style? Are they working on the same way?

Translate
CarlosCanto
Community Expert
Community Expert
Jun 12, 2025 3:24 PM UTC

yes, use the same concept for applying character styles

Translate