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
  • 20,448
  • 67
  • 204
  • 316
  • 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
  • 69,612
  • 13
  • 93
  • 124
0

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

morgancodes
  • 25,055
  • 38
  • 135
  • 187