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):
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
Post a Comment