Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Trevor Austin
/
mpcs-52553-austin-winter-2021
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Pipelines
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
16ef325b
authored
Feb 03, 2021
by
Trevor Austin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Dom manipulation to add an image
parent
c64be12d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
week_4/examples/dommanipulation.html
week_4/examples/dommanipulation.html
View file @
16ef325b
...
...
@@ -9,10 +9,11 @@
<input
type=
"button"
onclick=
"recolor('testing_ground')"
value=
"Colorize!"
></input>
<ol
id=
"mylist"
>
<li>
First item
</li>
</ol>
<button
onclick=
"addListItem();"
>
Add List Item
</button>
<input
id=
"imageurl"
></input>
<button
onclick=
"addListItem();"
>
Add Image
</button>
<script>
...
...
@@ -24,12 +25,14 @@
function
addListItem
()
{
var
list
=
document
.
body
.
querySelector
(
"#mylist"
);
var
newitem
=
document
.
createElement
(
"li"
);
var
newcontent
=
document
.
createTextNode
(
"New element!"
);
var
li
=
document
.
createElement
(
"li"
);
var
img
=
document
.
createElement
(
"img"
);
var
url
=
document
.
body
.
querySelector
(
"#imageurl"
).
value
;
newitem
.
appendChild
(
newcontent
);
img
.
setAttribute
(
"src"
,
url
);
list
.
appendChild
(
newitem
);
li
.
appendChild
(
img
);
list
.
appendChild
(
li
);
}
</script>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment