javascript - html jquery data attribute -


I have completely devoted to keeping default data / text, so I can retrieve it with jquery I can get rid of static text again and message in Jquery etc. This works, and I have a place to edit the text , but maybe it's pretty dirty, I'm not sure.

Similar (html):

"yesstyle", "notext": "No thanks." "Yes," yes "" yes "" yes " "," Noclass ":" nostile "} '>

then I have jquery in:

  Data ("data") yestext; someelement.removeClass ($ ('$ defaultdata') data ("data") noclass (someclass == 'yes') {someelement.text ($ ('$ defaultdata') ..); yesclass data ("data") to someelement.addClass ($ ('# defaultdata'));} Else {someelement.text ($ ('# defaultdata'). Data ("data"). ); Data to anyelement.removeClass ($ ('# defaultdata'); data ("data") yesclass ..); someelement.addClass ($ ('# defaultdata') noclass data ("data");} < / Code> 

My question is. Is not it better to get data ("Data") once! (As can be json?) And then that instead of multiple data ("data"). Xxxx request?

I mean. Jquery Scans, Selection and Pars Not every time I refer to the data ("data"), or is it already set in an array / object?

Combining charletflow and will, you have something similar:

  var someelement = $ (" # someelement "); Var default data = $ ('# defaultdata'). Data ('data'); If (someclass == 'yes') {someelement.text (defaultData.yestext) .removeClass (defaultData.noclass) .addClass (defaultData.yesclass); } And {someelement.text (defaultData.notext) .removeClass (defaultData.yesclass) .addClass (defaultData.noclass); }  

Here is a jsfiddle:


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -