javascript - jQuery and CSS selectors -


in past used following code take take text in data-placeholder attribute , use placeholder text div.

[contenteditable=true]:empty:not(:focus):before {     content:attr(data-placeholder) } 

this worked great, in current project need same thing except it's entirely built using jquery. know jquery has .empty(), .before(), :not(), , .focus() functions. way jquery selectors work, possible use css selector in jquery selector so?

var div = $([contenteditable=true]:empty:not(:focus):before); 

if not, there better way when working many functions?

simple solution append style tag:

var rule ='[contenteditable=true]:empty:not(:focus):before {'+    ' content:attr(data-placeholder)'+ '}'; $('head').append('<style>'+rule +'</style>'); 

Comments