| Simply put: Getting the user's name | |
|---|---|
| Tweet Topic Started: Thursday, 7. July 2011, 14:05 (380 Views) | |
| Joe | Thursday, 7. July 2011, 14:05 Post #1 |
![]()
Hi.
|
[bbc_code]$('div#top_info strong a').text();[/bbc_code] This snippet will simply grab the username of who is currently logged in. For example, if I ran that, it would return "Joe" as a string. You could also make it a nice little variable, though not necessary, like so.[bbc_code]var username = $('div#top_info strong a').text();[/bbc_code] With that, let's create a small `if` statement for a simple match.[bbc_code]if ($('div#top_info strong a').text() == 'Joe') { alert('Hi Joe!'); // Yay, it's a match! } else { alert('You\'re not Joe!'); // Looks like it wasn't a match..! }[/bbc_code] * Simply states the element is a div, and to look only for divs - nothing else. Try to include this in your coding. Efficiency, yes! * The div id is `top_info`, thus we used a `#` symbol instead of a period. * The text we're looking for - the username - has the `<strong>` tags around it. Perfect! * The text we're looking for is also a link, so we use `a` to narrow things down even more. * Simply returns what we found as a string. Also, if you went with the variable option.[bbc_code]if (username == 'Joe') { alert('Hi Joe!'); // Yay, it's a match! } else { alert('You\'re not Joe!'); // Looks like it wasn't a match..! }[/bbc_code] |
| Joe | |
Off
Profile |
Quote Top
|
| Oracle | Friday, 8. July 2011, 04:52 Post #2 |
![]()
Level 8
|
Why do you include the \ in the 'You\'re'? |
Visit my shop! Forum reviews, posting packages, recolors![]() ![]() ![]() Me! | |
Off
Profile |
Quote Top
|
| Sith... | Friday, 8. July 2011, 07:18 Post #3 |
Level 4
|
So apostrophe is displayed and the string doesn't end, I'd assume... Edited by Sith..., Friday, 8. July 2011, 07:19.
|
Off
Profile |
Quote Top
|
| Oracle | Friday, 8. July 2011, 07:35 Post #4 |
![]()
Level 8
|
I guess so, thanks.
|
Visit my shop! Forum reviews, posting packages, recolors![]() ![]() ![]() Me! | |
Off
Profile |
Quote Top
|
| Aidan | Sunday, 7. August 2011, 14:30 Post #5 |
![]()
Level 12
|
Outline Documentations T H E M E S Documentation accepted in to the Themes database |
Off
Profile |
Quote Top
|
| 1 user reading this topic (1 Guest and 0 Anonymous) | |
| « Previous Topic · Coding & Development · Next Topic » |
| Track Topic · E-mail Topic |
8:15 PM Jul 10
|
Powered by ZetaBoards Premium · Privacy Policy



Multi
Multi





Thank you Brendan for the image! 

8:15 PM Jul 10


Outline Live