/    Sign up×
Community /Pin to ProfileBookmark

allow user to modify a function

Hi:

I have this function which changes the color of text, according to the text class:

[FONT=Courier New]function colorLine(clss) {
$(‘.’ + clss).animate( {color:’#CD0000′}, 1200 );
}
[/FONT]

The function is used as part of a four-way switch function, and this switch function itself is repeated.

I’m looking for a way to have the viewer–before the switch function is called–to choose from several colors, eg yellow, blue, green, black, by clicking on appropriate links.

If I add another variable for the color, still not sure how I’d access that?

Any suggestions welcome.

to post a comment
JavaScript

11 Comments(s)

Copy linkTweet thisAlerts:
@LesshardtoofindSep 16.2017 — You could use some settings object to store user settings? You could also just dynamically change the color on the fly by adding or removing the css class when the user changes it rather than "waiting" for the switch statement to run. Without a larger code example of the scenario it is nearly impossible for me to give you a solution idea w/o just programming it for you.
Copy linkTweet thisAlerts:
@rootSep 16.2017 — Moved to JavaScript Frameworks (because thats JQuery not Javascript).
Copy linkTweet thisAlerts:
@sapioitSep 16.2017 — JQuery or not, it could be anything in the function. The problem he/she/it has is that the content of the class to change, which has much more to do with JS than has with a JS framework (aside from being able to be used in a JS framework).

[B]@Oddjob41[/B] You could try having a global variable, and a switch (or set of IFs) depending on that global would run the appropriate code for each case.


[FONT=Book Antiqua][SIZE=1][COLOR="#D3D3D3"]I'm starting to doubt your quality as a moderator...[/COLOR][/SIZE][/FONT]
Copy linkTweet thisAlerts:
@Oddjob41authorSep 16.2017 — [I][B]@Oddjob41[/B] You could try having a global variable, and a switch (or set of IFs) depending on that global would run the appropriate code for each case.[/I]

Great, many thanks. This was about where I'd gotten to thinking it through, but haven't yt tried--a set of if...else if...etc.
Copy linkTweet thisAlerts:
@rootSep 16.2017 — JQuery or not, it could be anything in the function. The problem he/she/it has is that the content of the class to change, which has much more to do with JS than has with a JS framework (aside from being able to be used in a JS framework).

[B]@Oddjob41[/B] You could try having a global variable, and a switch (or set of IFs) depending on that global would run the appropriate code for each case.


[FONT=Book Antiqua][SIZE=1][COLOR="#D3D3D3"]I'm starting to doubt your quality as a moderator...[/COLOR][/SIZE][/FONT][/QUOTE]


JavaScript within JQuery is part of the JQuery function... Therefore it is considered to be JQuery. You get some people arguing that its the same thing as JavaScript when the simple test is to just write a JQuery function and a JavaScript equivalent and see which one runs in the browser, if it won't run then its JQuery because you have to load a lump of data called JQuery in to the browser before you can run any JQuery code.

JQuery is written in JavaScript, that does not make it JavaScript or any of the bugs in code in functions that are related to running JQuery.
Copy linkTweet thisAlerts:
@sapioitSep 17.2017 — This might be nitpicking, but if the code example he gave was with jQuery and he asked for an answer in the JS category, without mention of the requiring answer needing to be in JQuery, then the jQuery is just some example unrelated to the question at hand.

That's business logic, which might be in any framework, even just as a (random) library that does the same thing as the code in the example.

But that's just my 2 cents...

[B][I]@Oddjob41[/I][/B] Glad I could be of assistance!
Copy linkTweet thisAlerts:
@sapioitSep 17.2017 — *required answer

[SIZE=2][COLOR="#808080"](that's why an edit button would be great)[/COLOR][/SIZE]
Copy linkTweet thisAlerts:
@rootSep 17.2017 — If you have a JQuery script, when you look at it, most of the JavaScript in the script is within a function(){} element within a JQuery call. Any external JavaScript accompanying JQuery scripts is treated as JQuery as it is often there where the problem lies, something in the JQuery and the JQuery has its own forum so that the JavaScript forum is not littered with usless JQuery type help requests.

Thats what was happening, the JavaScript forum was being cluttered with non JavaScript issues, the sub forum for these queries was born because you couldn't get a JavaScript answer for JQuery getting in the way.
Copy linkTweet thisAlerts:
@Oddjob41authorSep 18.2017 — @ Sapioit, thanks for Balalaika, could be about my speed.

I assumed the solution would be js not jQ. I'd considered posting on the jQuery getting started forum, but thought I'd be told [I]not a jQ question[/I].

Appreciate the moderator's position.
Copy linkTweet thisAlerts:
@savitasandeepDec 02.2017 — I would here give a drop down list for colors which users can select and then change the color of the text based on it.
Copy linkTweet thisAlerts:
@Oddjob41authorDec 03.2017 — I would here give a drop down list for colors which users can select and then change the color of the text based on it.[/QUOTE]

There’s a test version now, with five elements on which the colour can be changed, using two basic techniques:

fade in upper layer > change colour in layer below > fade out upper layer—used for backgrounds;

a hidden element changes colour, and a series of ‘if’ statements change the colour of a target element—as suggested by[B] sapioit[/B];

wavehands.net > changes > test.htm > ask > colour.

There are two hidden elements: these are visible in test mode, the two “eyes”, below “colour”.

Cheers
×

Success!

Help @Oddjob41 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...