0
$("textarea").cleditor({ width: "800px", height: "300px" })[0].focus();

but when i do not have textarea felad i get

Error: $("textarea").cleditor({width: "800px", height: "300px"})[0] is undefined

how can i check if textarea field exist.

I try ($("textarea").val()) but not working correctly. I also try value() but also not working. How can i check if exist or not?

senzacionale
  • 19,912
  • 67
  • 198
  • 310
  • 1
    Duplicated of http://stackoverflow.com/questions/31044/is-there-an-exists-function-for-jquery – v42 Nov 22 '11 at 18:39

2 Answers2

5

Use length property of jQuery object which is non zero if it finds any element. Try this

if($("textarea").length > 0){
   //your code here
}
ShankarSangoli
  • 68,720
  • 11
  • 89
  • 123
0

var $textArea = $("textarea"); if($textArea.length > 0){ $textArea.cleditor({ width: "800px", height: "300px" })[0].focus(); }

morgancodes
  • 24,623
  • 37
  • 132
  • 186