inherit
24252
0
Aug 1, 2023 15:01:24 GMT -8
coolcoolcool
When the world says, "Give up," Hope whispers, "Try it one more time."
2,148
May 2004
coolcoolcool
|
Post by coolcoolcool on Jun 20, 2012 9:13:08 GMT -8
If there's more than one line in an if-statement you need curly braces.
for(var img = document.getElementsByTagName("img"), i = 0; i < img.length;i++) { if(img.alt.match(/\[add bookmark\]/i)) { link = document.createElement("a"); link.href="#bottom"; image = document.createElement("image"); image.alt="[whatevs]"; image.title="[whatevs]"; image.src="image.png"; link.appendChild(image); img.parentNode.parentNode.appendChild(link); } }
|
|
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 Jun 20, 2012 9:26:18 GMT -8
Alright I thought it needed them lol.
|
|
inherit
130228
0
Jul 11, 2024 19:19:59 GMT -8
Charles Stover
1,731
August 2008
gamechief
|
Post by Charles Stover on Jun 23, 2012 14:00:35 GMT -8
innerHTML is a property of elements. Any element. It can be an element with an ID, it can be an element you retrieved by tag name, it can be firstChild, etc.
It's just a string. Nothing special. A string. Just like var str = "my string"; innerHTML is a string like that. It contains HTML as a string. var someInnerHTML = "<b>my HTML</b>";
.match() is a property of strings. It applies to all strings. Not just innerHTML.
innerHTML doesn't have any properties that all other strings don't also share.
alert("string".match(/^str/));
<body><div id="test">this is <span>the innerHTML</span> of the div element</div></body>
So you get the <div> element, however you want to get it: document.getElementById("test") document.getElementsByTagName("div").item(0) document.body.firstChild
All of those return the exact same element. They are all equivalent, even though you retrieved the div in different ways. Just like 1 + 1 = 3 - 1. Different ways of getting the same result.
Now that you have the div, it's innerHTML is a string: this is <span>the innerHTML</span> of the div element
alert(div.innerHTML == "this is <span>the innerHTML</span> of the div element"); // true
|
|
inherit
King Oligochaete
126470
0
Feb 24, 2021 12:23:15 GMT -8
Wormopolis
Stop rating plugins with 1 star that dont deserve it.
20,002
June 2008
tbserialkillers
Wormo's Mini-Profile
|
Post by Wormopolis on Jun 27, 2012 23:26:41 GMT -8
keep in mind that if you change the innerHTML of an element, IE only allows certain KIDS of elements to be changed, like TD SPAN DIV FONT P etc.. if you try to change table or a tbody or a tr it throws an error
|
|