inherit
170346
0
Mar 1, 2016 12:53:37 GMT -8
Shorty
Yeah, I'm that cool. Lol! No I'm not.
3,018
August 2011
shortyverrett94
|
Post by Shorty on Jul 30, 2012 8:10:39 GMT -8
How can you get an <a> element that has a certian href? Is it possible? Thanks!!!
|
|
#00AF33
Bark Different.
102833
0
1
Feb 12, 2023 16:57:46 GMT -8
RedBassett
I'm a Marxist/Lennonist of the Groucho/John variety.
15,405
April 2007
applecomputer
RedBassett's Mini-Profile
|
Post by RedBassett on Jul 30, 2012 17:52:31 GMT -8
How can you get an <a> element that has a certian href? Is it possible? Thanks!!! var elements = document.getElementsByTagName('a'); for (var i = 0; i < elements.length; i++) { if (elements .href=='something') { // Code } }
|
|
inherit
170346
0
Mar 1, 2016 12:53:37 GMT -8
Shorty
Yeah, I'm that cool. Lol! No I'm not.
3,018
August 2011
shortyverrett94
|
Post by Shorty on Jul 30, 2012 18:00:30 GMT -8
Alright. So can I use this method to add something after a button?
|
|
#00AF33
Bark Different.
102833
0
1
Feb 12, 2023 16:57:46 GMT -8
RedBassett
I'm a Marxist/Lennonist of the Groucho/John variety.
15,405
April 2007
applecomputer
RedBassett's Mini-Profile
|
Post by RedBassett on Jul 30, 2012 18:02:12 GMT -8
With a little more DOM manipulation, yes.
|
|
inherit
170346
0
Mar 1, 2016 12:53:37 GMT -8
Shorty
Yeah, I'm that cool. Lol! No I'm not.
3,018
August 2011
shortyverrett94
|
Post by Shorty on Jul 30, 2012 18:03:46 GMT -8
What do you mean?
|
|
#00AF33
Bark Different.
102833
0
1
Feb 12, 2023 16:57:46 GMT -8
RedBassett
I'm a Marxist/Lennonist of the Groucho/John variety.
15,405
April 2007
applecomputer
RedBassett's Mini-Profile
|
Post by RedBassett on Jul 30, 2012 18:05:06 GMT -8
If you want to insert it after (not inside) and a element, you will need to insert whatever you want to add as the next child of the parent element (I believe, thanks to JQuery I haven't done any of this in a while).
|
|
inherit
170346
0
Mar 1, 2016 12:53:37 GMT -8
Shorty
Yeah, I'm that cool. Lol! No I'm not.
3,018
August 2011
shortyverrett94
|
Post by Shorty on Jul 30, 2012 18:08:28 GMT -8
Oh okay. I kind of thought that is what you meant. Alright probably noobish but say i want to set that certain link as a variable. Would do this?
var elements = document.getElementsByTagName('a'); for (var i = 0; i < elements.length; i++) { if (elements.href=='something') { var link = elements; } }
|
|
#00AF33
Bark Different.
102833
0
1
Feb 12, 2023 16:57:46 GMT -8
RedBassett
I'm a Marxist/Lennonist of the Groucho/John variety.
15,405
April 2007
applecomputer
RedBassett's Mini-Profile
|
Post by RedBassett on Jul 31, 2012 4:47:03 GMT -8
Yes
|
|
inherit
170346
0
Mar 1, 2016 12:53:37 GMT -8
Shorty
Yeah, I'm that cool. Lol! No I'm not.
3,018
August 2011
shortyverrett94
|
Post by Shorty on Jul 31, 2012 5:00:59 GMT -8
And I would put the rest I my code outside the brackets or inside? Sorry! And thank you again!
|
|
#00AF33
Bark Different.
102833
0
1
Feb 12, 2023 16:57:46 GMT -8
RedBassett
I'm a Marxist/Lennonist of the Groucho/John variety.
15,405
April 2007
applecomputer
RedBassett's Mini-Profile
|
Post by RedBassett on Jul 31, 2012 5:47:38 GMT -8
Depends on what you are doing. If you are just doing something simple, yes. If you want to reference the element later, no. The variable will stay in scope outside the loop.
|
|
inherit
170346
0
Mar 1, 2016 12:53:37 GMT -8
Shorty
Yeah, I'm that cool. Lol! No I'm not.
3,018
August 2011
shortyverrett94
|
Post by Shorty on Jul 31, 2012 7:06:58 GMT -8
Okay. So of I want to reference it later should I put the code right below the link variable or between the two closing brackets?
|
|
#00AF33
Bark Different.
102833
0
1
Feb 12, 2023 16:57:46 GMT -8
RedBassett
I'm a Marxist/Lennonist of the Groucho/John variety.
15,405
April 2007
applecomputer
RedBassett's Mini-Profile
|
Post by RedBassett on Jul 31, 2012 14:31:33 GMT -8
Doesn't really matter where.
Either way, the variable will still be available later on.
|
|