|
Hi everybody! Please let me know if this isn't the place to ask. Skill level: Pretty beginner, I have the basic concepts of HTML 5 and CSS down, with some JS Project Requirements: Probably CSS and JS Would anyone mind helping me out? I'd be very grateful! I'd even be happy with a point in the right direction. I'm looking for a simple, clean way to switch between different sets of text. Ideally I'd like to have a set of radio buttons at the top to let the user switch between three sets of text scattered throughout a page. The way I know how to do it would involve hiding each individual instance of all txtB and txtC while the txtA button is depressed, and that seems like it can get tedious and messy as far as code goes. I feel like there's got to be a better way for me to group everything according to type and use some buttons to toggle which values are shown. Simple code: code:
Text A./Text B./Text C. Universal Text Text A./Text B./Text C. Universal Text Any input would be AWESOME.
|
# ¿ Jul 11, 2016 22:57 |
|
|
# ¿ May 20, 2024 02:49 |
|
PT6A posted:Assign a CSS class to each set of text (let's say "textA" "textB" "textC" to keep things simple). When a radio button is selected, set the two non-active classes to have "display:none" in CSS, and the active class to have "display:block". That's a great start! Thanks! Let me see if I can do it with that!
|
# ¿ Jul 12, 2016 00:25 |
|
Depressing Box posted:You could also lean more on CSS and write a style that hides all conditional elements, then show the elements that match the parent class: So close! I hate to ask for help again so soon but this is driving me nuts. My JS skills aren't quite up to snuff, apparently, and I'm having a hell of a time figuring out the IF statement's syntax (if I should even be using IF statements for what I'm doing). Here's what I have so far. To simplify I just lumped the CSS in the main code. Can anyone spot what I'm doing wrong? code:
|
# ¿ Jul 12, 2016 03:28 |
|
Depressing Box posted:Mixing CSS and JS like that won't actually do anything. I'd recommend reading some introductory JavaScript tutorials to get familiar with how the language is structured (I've found Eloquent Javascript to be pretty straightforward, and it's free). That's great! It's exactly what I want it to do! And you're right, I definitely need to get more familiar with Javascript. I'm trying to run before I can walk. In the meanwhile, where do I place that JS code so it works? I've tried copying it directly in <SCRIPT> brackets in the HEAD and BODY sections and that doesn't work so I'm fairly certain I'm doing that wrong too.
|
# ¿ Jul 12, 2016 19:29 |
|
Depressing Box posted:You need to include jQuery first, and I recommend putting both at the very bottom of the page, just before the closing </body> tag, like so. Loading scripts last keeps them from slowing down the initial page load, and makes it so you don't (or very rarely) need to wait for the window.onload event. You are an amazing person. You deserve a raise and a back-rub. Thank you!
|
# ¿ Jul 12, 2016 19:52 |