<HTML>
<body>
<head>
<style>
/* # => select the element BY ITS ID*/
#contents {
padding:5px;
border:1px green solid;
}
</style>
</head>
<fieldset id="contents">
<legend>#contents</legend> //legend is for title
<p>
How about to read <a href="http://wikipedia.org">Wikipedia</a> or visit <a href="http://w3.org"><i>W3.org</i></a> and learn about modern standards?
</p>
</fieldset>
<script>
contents.onclick = function(event) {
function handleLink (href) {
let isLeaving = confirm(`Leave for ${href}`);
/*confirm pops yes or no window*/
if (!isLeaving) return false;
/*if user clicked no, isLeaving becomes false, link canceled*/
}
let target = event.target.closest('a');
/*closest traverses parents(heading towards the doc root)
until it finds a tag, it will resturn itself or matching ancestor */
//target = a tag
if(target && contents.contains(target)) {
//if it is a target AND it contains a????
return handleLink(target.getAttribute('href'));
/*since the confirming window refers to the href to ask leaving or not,
it should be passed for line 24
*/
}
};
</script>
</body>
</HTML>
<body>
<head>
<style>
/* # => select the element BY ITS ID*/
#contents {
padding:5px;
border:1px green solid;
}
</style>
</head>
<fieldset id="contents">
<legend>#contents</legend> //legend is for title
<p>
How about to read <a href="http://wikipedia.org">Wikipedia</a> or visit <a href="http://w3.org"><i>W3.org</i></a> and learn about modern standards?
</p>
</fieldset>
<script>
contents.onclick = function(event) {
function handleLink (href) {
let isLeaving = confirm(`Leave for ${href}`);
/*confirm pops yes or no window*/
if (!isLeaving) return false;
/*if user clicked no, isLeaving becomes false, link canceled*/
}
let target = event.target.closest('a');
/*closest traverses parents(heading towards the doc root)
until it finds a tag, it will resturn itself or matching ancestor */
//target = a tag
if(target && contents.contains(target)) {
//if it is a target AND it contains a????
return handleLink(target.getAttribute('href'));
/*since the confirming window refers to the href to ask leaving or not,
it should be passed for line 24
*/
}
};
</script>
</body>
</HTML>
댓글
댓글 쓰기