• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 09:26
CEST 15:26
KST 22:26
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL20] Ro24 Preview Pt1: Runway112v2 & SC: Evo Complete: Weekend Double Feature3Team Liquid Map Contest #21 - Presented by Monster Energy9uThermal's 2v2 Tour: $15,000 Main Event18Serral wins EWC 202549
Community News
Weekly Cups (Aug 11-17): MaxPax triples again!10Weekly Cups (Aug 4-10): MaxPax wins a triple6SC2's Safe House 2 - October 18 & 195Weekly Cups (Jul 28-Aug 3): herO doubles up6LiuLi Cup - August 2025 Tournaments7
StarCraft 2
General
RSL Revival patreon money discussion thread Is it ok to advertise SC EVO Mod streaming here? Maestros of the Game 2v2 & SC: Evo Complete: Weekend Double Feature Playing 1v1 for Cash? (Read before comment)
Tourneys
Master Swan Open (Global Bronze-Master 2) $5,100+ SEL Season 2 Championship (SC: Evo) Sparkling Tuna Cup - Weekly Open Tournament RSL: Revival, a new crowdfunded tournament series LiuLi Cup - August 2025 Tournaments
Strategy
Custom Maps
External Content
Mutation # 487 Think Fast Mutation # 486 Watch the Skies Mutation # 485 Death from Below Mutation # 484 Magnetic Pull
Brood War
General
BW General Discussion Flash Announces (and Retracts) Hiatus From ASL ASL 20 HYPE VIDEO! New season has just come in ladder [ASL20] Ro24 Preview Pt1: Runway
Tourneys
[ASL20] Ro24 Group C [ASL20] Ro24 Group B [Megathread] Daily Proleagues [ASL20] Ro24 Group A
Strategy
Simple Questions, Simple Answers Fighting Spirit mining rates [G] Mineral Boosting Muta micro map competition
Other Games
General Games
Beyond All Reason Stormgate/Frost Giant Megathread Nintendo Switch Thread Total Annihilation Server - TAForever [MMORPG] Tree of Savior (Successor of Ragnarok)
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
Russo-Ukrainian War Thread US Politics Mega-thread Things Aren’t Peaceful in Palestine European Politico-economics QA Mega-thread The Games Industry And ATVI
Fan Clubs
INnoVation Fan Club SKT1 Classic Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2026 Football Thread TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
Gtx660 graphics card replacement Installation of Windows 10 suck at "just a moment" Computer Build, Upgrade & Buying Resource Thread
TL Community
TeamLiquid Team Shirt On Sale The Automated Ban List
Blogs
The Biochemical Cost of Gami…
TrAiDoS
[Girl blog} My fema…
artosisisthebest
Sharpening the Filtration…
frozenclaw
ASL S20 English Commentary…
namkraft
StarCraft improvement
iopq
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1739 users

The Big Programming Thread - Page 351

Forum Index > General Forum
Post a Reply
Prev 1 349 350 351 352 353 1031 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
HardlyNever
Profile Blog Joined July 2011
United States1258 Posts
September 11 2013 14:51 GMT
#7001
That's what the href in the buttons and the div ids are for. Change the href in the button to whatever div id you want it to affect.

So like:

<button type="button" href="#collapse1" class="nav-toggle">Button 1</button>
<div id="collapse1" style="display:none;">
<p>stuff for #1 here</p>
</div>

<button type="button" href="#collapse2" class="nav-toggle">Button 2</button>
<div id="collapse2" style="display:none;">
<p>stuff for #2 here</p>
</div>
Out there, the Kid learned to fend for himself. Learned to build. Learned to break.
Yoshi-
Profile Joined October 2008
Germany10227 Posts
Last Edited: 2013-09-11 15:04:22
September 11 2013 15:04 GMT
#7002
Buttons don't have a "href" attribute.
tofucake
Profile Blog Joined October 2009
Hyrule19060 Posts
September 11 2013 16:09 GMT
#7003
Doesn't matter. You can make up attributes. Hell, you could use "divtohide" as an attribute, and get the value with prop() or attr()
Liquipediaasante sana squash banana
Yoshi-
Profile Joined October 2008
Germany10227 Posts
September 11 2013 16:14 GMT
#7004
On September 12 2013 01:09 tofucake wrote:
Doesn't matter. You can make up attributes. Hell, you could use "divtohide" as an attribute, and get the value with prop() or attr()


Only allowed in html5, and even then this is just bad practice
misirlou
Profile Joined June 2010
Portugal3238 Posts
September 11 2013 16:16 GMT
#7005
On September 12 2013 01:14 Yoshi- wrote:
Show nested quote +
On September 12 2013 01:09 tofucake wrote:
Doesn't matter. You can make up attributes. Hell, you could use "divtohide" as an attribute, and get the value with prop() or attr()


Only allowed in html5, and even then this is just bad practice


Yeah, and if using HTML5, Data-X is the way to do that.
tofucake
Profile Blog Joined October 2009
Hyrule19060 Posts
September 11 2013 16:17 GMT
#7006
Never said it wasn't, but it's a way of doing it.
Liquipediaasante sana squash banana
HardlyNever
Profile Blog Joined July 2011
United States1258 Posts
September 11 2013 16:19 GMT
#7007
On September 12 2013 00:04 Yoshi- wrote:
Buttons don't have a "href" attribute.


Technically no, but it works. If you're on a browser that doesn't support html 5, well, yeah...

I was just trying to give the guy a workable solution. If you want to give him a "better" one, feel free.
Out there, the Kid learned to fend for himself. Learned to build. Learned to break.
Yoshi-
Profile Joined October 2008
Germany10227 Posts
September 11 2013 16:28 GMT
#7008
On September 12 2013 01:19 HardlyNever wrote:
Show nested quote +
On September 12 2013 00:04 Yoshi- wrote:
Buttons don't have a "href" attribute.


Technically no, but it works. If you're on a browser that doesn't support html 5, well, yeah...

I was just trying to give the guy a workable solution. If you want to give him a "better" one, feel free.


Yea there is a lot of stuff that works in just fine(no doctype, not closing tags) and that you still shouldn't do, especially since "href" normally indicates a link. And what happens if they suddenly add the href tag to buttons? Then it is suddenly broken.

And and the two best options have already been posted, calling the div directly using the id or in the relation to what was clicked.
HardlyNever
Profile Blog Joined July 2011
United States1258 Posts
September 11 2013 16:38 GMT
#7009
Then feel free to post a working solution with that method.

Or you could just keep adding nothing constructive and keep nay-saying about how everything is wrong, like half the people that post in this thread.

The guy who asked the question can choose what he wants to do. It's not like I'm forcing him to use what I posted, it is just an option. Why don't you give him a better working option, rather than just criticizing?
Out there, the Kid learned to fend for himself. Learned to build. Learned to break.
Yoshi-
Profile Joined October 2008
Germany10227 Posts
September 11 2013 16:54 GMT
#7010
On September 12 2013 01:38 HardlyNever wrote:
Then feel free to post a working solution with that method.

Or you could just keep adding nothing constructive and keep nay-saying about how everything is wrong, like half the people that post in this thread.

The guy who asked the question can choose what he wants to do. It's not like I'm forcing him to use what I posted, it is just an option. Why don't you give him a better working option, rather than just criticizing?



What is less constructive posting a flawed solution or pointing out the flaw?
HardlyNever
Profile Blog Joined July 2011
United States1258 Posts
September 11 2013 16:59 GMT
#7011
Criticizing a working solution, without posting a better working solution, is definitely less constructive.
Out there, the Kid learned to fend for himself. Learned to build. Learned to break.
Yoshi-
Profile Joined October 2008
Germany10227 Posts
September 11 2013 17:05 GMT
#7012
On September 12 2013 01:59 HardlyNever wrote:
Criticizing a working solution, without posting a better working solution, is definitely less constructive.


There already is a working solution, that is perfectly fine and posting another one would just be redundant, and because of that not constructive.

Your solution is flawed and I pointed out the flaw, dunno how you could say that my post is less constructive than your original post.

And when you have such an hatred against non-constructiveness then why do you even argue in this thread, because this conversation is as useless as it can get.
supereddie
Profile Joined March 2011
Netherlands151 Posts
Last Edited: 2013-09-11 17:12:07
September 11 2013 17:11 GMT
#7013
On September 11 2013 20:37 adwodon wrote:
Got roped into doing a bit of webstuff by my boss, not sure why as it's not my specialty, but I told him you could easily show / hide sections of text so he decided that means I'm the web guy now.

On that note I have this:


<script language="JavaScript" type="text/javascript">
function blocking(nr)
// for displaying or hiding parts of the page
{
displayNew = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';
document.getElementById(nr).style.display = displayNew;
}
</script>


Then I have it used as follows:


<div>
Something <a href="" onclick="blocking('showHide1'); return false;">+</a>
<div id="showHide1">
Write text here...
</div>
</div>

<div>
Something else <a href="" onclick="blocking('showHide2'); return false;">+</a>
<div id="showHide2">
Write text here...
</div>
</div>


My question is straight forward enough, do I need to have showHide1 and showHide2 or can I do something to keep all the id's the same but still only act on the correct div tag. The way I have it working now is messy and I don't like it at all.

Appreciate any help

Very simple: just pass 'this' as parameter to your javascript function as the sender, like this

function toggle(sender) {
var elm = sender.getElementsByClassName("someID")[0];
elm.style.display = elm.style.display == 'none' ? 'block' : 'none';
}


Then, on the parent element, you call "toggle(this)":

<div class="showHide" onclick="toggle(this)">Some text
<div class="someID">Write text here...</div>
</div>
<div class="showHide" onclick="toggle(this)">Sometext
<div class="someID">Write text here...</div>
</div>


No need for bloated jquery.
"Do not try to make difficult things possible, but make simple things simple." - David Platt on Software Design
HardlyNever
Profile Blog Joined July 2011
United States1258 Posts
September 11 2013 17:13 GMT
#7014
On September 12 2013 02:05 Yoshi- wrote:
Show nested quote +
On September 12 2013 01:59 HardlyNever wrote:
Criticizing a working solution, without posting a better working solution, is definitely less constructive.


There already is a working solution, that is perfectly fine and posting another one would just be redundant, and because of that not constructive.

Your solution is flawed and I pointed out the flaw, dunno how you could say that my post is less constructive than your original post.

And when you have such an hatred against non-constructiveness then why do you even argue in this thread, because this conversation is as useless as it can get.


Because half this thread is useless arguing, and I'm hoping that by pointing it out, to maybe change that. Maybe it is more useless arguing.

The only other solution posted didn't have functioning buttons, or a way to differentiate between the divs, like the guy needed. If he can take that and make buttons and separate ids with it, then fine, no problem. It wasn't exactly what he needed (it seemed) so I put what I had working.

I'm just tired of coming to this thread and seeing people constantly saying how things are wrong, without providing anyway to do it. It does nothing, it's just asshattery.
Out there, the Kid learned to fend for himself. Learned to build. Learned to break.
tofucake
Profile Blog Joined October 2009
Hyrule19060 Posts
September 11 2013 18:08 GMT
#7015
Pretty sure my solution had functioning buttons with differentiation between divs.

But there are plenty of people who know enough to say "that's not following the rules, even it works" but don't have the experience to provide a solution which does follow the rules. There's no need to get upset.
Liquipediaasante sana squash banana
HardlyNever
Profile Blog Joined July 2011
United States1258 Posts
September 11 2013 18:24 GMT
#7016
All I saw was this:

http://jsfiddle.net/yW7Yz/2/

Which didn't have buttons, or div ids (just classes). Was there something else? Either way, it seems like the guy got what he wanted, so alls-well that ends-well.
Out there, the Kid learned to fend for himself. Learned to build. Learned to break.
berated-
Profile Blog Joined February 2007
United States1134 Posts
September 12 2013 01:34 GMT
#7017
On September 12 2013 03:08 tofucake wrote:
Pretty sure my solution had functioning buttons with differentiation between divs.

But there are plenty of people who know enough to say "that's not following the rules, even it works" but don't have the experience to provide a solution which does follow the rules. There's no need to get upset.


Getting upset and useless arguing is one of the best parts of programming, don't try to discourage...

With all these opinions one more can't hurt.


no need for bloated jquery


Hmm. This seems like bad advice. Why would you want to take the time that your js works perfectly in every browser when most web devs are doing it for you by using jquery? Use a cdn, use gzip compression, its not that big.

To the people binding the click event to the div, doesn't it feel weird? Call me old school, I prefer to use click events on things that normally support click like links and buttons but I got my start in web dev with an eye towards accessibility standards.

On making up attributes...it used to be the only way, but with data-* in html5, as a few mentioned, it just feels bizarre to suggest making up anything other than a data-* attribute. If you are going to make a name up, just always append data- in front of it and it is now valid in html5, seems easy enough.


should have buttons or something. You could probably do toggle on first child instead if you want to have a bunch of .showHides

http://jsfiddle.net/yW7Yz/2/ like that


This is sound advice, with a slight modification. I have found that things like first child, direct descendent selects, next() ,previous(), parent() and sibling() in jquery are just a tad brittle because they require the exact markup structure not to change. If you are positive that you aren't going to change it in the future then of course you're fine.

Using closest() and find() in combination alleviates some of the pain. It is worth noting that lots of dom traversal is still bad -> so this is great for show hide types where you just want to operate in context of an item getting clicked, and not so great say when used in a loop of a few thousand iterations.

Example: http://jsfiddle.net/ReWEj/
wowguideding
Profile Joined September 2013
3 Posts
September 12 2013 07:43 GMT
#7018
--- Nuked ---
supereddie
Profile Joined March 2011
Netherlands151 Posts
September 12 2013 16:06 GMT
#7019
On September 12 2013 10:34 berated- wrote:
Hmm. This seems like bad advice. Why would you want to take the time that your js works perfectly in every browser when most web devs are doing it for you by using jquery? Use a cdn, use gzip compression, its not that big.

This particular problem can be easliy solved with standard javascript that is supported in all browsers. There are no browser-specific functions needed - just standard javascript. You don't need external files, libraries etc. Every function is builtin in the javascript engine in a browser. It is complete overkill to use jQuery for this simple problem.
"Do not try to make difficult things possible, but make simple things simple." - David Platt on Software Design
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
September 12 2013 21:45 GMT
#7020
I was wondering how variables' scope is dealt with in regards to Java GUI. Is it global or do you need to declare everything as a field? All in all, how you deal with variables? Examples would be nice if you have nearby.
Prev 1 349 350 351 352 353 1031 Next
Please log in or register to reply.
Live Events Refresh
WardiTV Summer Champion…
11:00
Group Stage 2 - Group B
Clem vs goblin
ByuN vs SHIN
WardiTV910
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Harstem 336
Rex 148
ProTech34
trigger 12
EnDerr 9
StarCraft: Brood War
Britney 49518
Calm 11658
Bisu 3280
Jaedong 1103
firebathero 772
EffOrt 755
BeSt 475
ggaemo 335
Stork 311
ZerO 243
[ Show more ]
Light 207
Last 203
Soulkey 178
Hyun 123
Snow 114
Barracks 113
Mind 98
hero 92
Rush 70
Nal_rA 67
TY 57
Movie 43
Backho 26
Icarus 25
Sharp 25
Yoon 21
sorry 20
Sacsri 16
JYJ15
JulyZerg 14
scan(afreeca) 13
IntoTheRainbow 7
Terrorterran 6
ivOry 3
actioN 0
Dota 2
Gorgc7464
qojqva2096
XcaliburYe264
Fuzer 210
League of Legends
Dendi975
Counter-Strike
hiko590
edward57
Super Smash Bros
Mew2King79
Other Games
singsing2022
B2W.Neo1889
DeMusliM482
crisheroes463
XaKoH 155
ToD86
ArmadaUGS67
QueenE37
Trikslyr30
ZerO(Twitch)2
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• davetesta14
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• HerbMon 35
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• WagamamaTV526
League of Legends
• Nemesis3419
• Jankos1086
Upcoming Events
Online Event
10h 34m
The PondCast
20h 34m
WardiTV Summer Champion…
21h 34m
Zoun vs Bunny
herO vs Solar
Replay Cast
1d 10h
LiuLi Cup
1d 21h
BSL Team Wars
2 days
Team Hawk vs Team Dewalt
Korean StarCraft League
2 days
CranKy Ducklings
2 days
SC Evo League
2 days
WardiTV Summer Champion…
2 days
Classic vs Percival
Spirit vs NightMare
[ Show More ]
CSO Cup
3 days
[BSL 2025] Weekly
3 days
Sparkling Tuna Cup
3 days
SC Evo League
3 days
BSL Team Wars
4 days
Team Bonyth vs Team Sziky
Afreeca Starleague
4 days
Queen vs HyuN
EffOrt vs Calm
Wardi Open
4 days
Replay Cast
5 days
Afreeca Starleague
5 days
Rush vs TBD
Jaedong vs Mong
Afreeca Starleague
6 days
herO vs TBD
Royal vs Barracks
Liquipedia Results

Completed

Jiahua Invitational
uThermal 2v2 Main Event
HCC Europe

Ongoing

Copa Latinoamericana 4
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
ASL Season 20
CSL Season 18: Qualifier 1
SEL Season 2 Championship
WardiTV Summer 2025
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025

Upcoming

CSLAN 3
CSL 2025 AUTUMN (S18)
LASL Season 20
BSL Season 21
BSL 21 Team A
Chzzk MurlocKing SC1 vs SC2 Cup #2
RSL Revival: Season 2
Maestros of the Game
EC S1
PGL Masters Bucharest 2025
MESA Nomadic Masters Fall
Thunderpick World Champ.
CS Asia Championships 2025
Roobet Cup 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.