This is my first post and I don't know what I am doing yet, so please bear with me.
I am trying to use vanilla JS to highlight a clicked anchor and remove the previously highlighted anchor.
I am not sure why it is not working but I am new at this.
My CodePen
below is just the JS. .nav-link is the link class. active is the class that should manipulate it after the click.
window.onload = afterClick;
function afterClick(){
//set an on off array to toggle.
let linkClass = document.querySelectorAll(".nav-link");
linkClass.forEach(link => link.addEventListener("click", function(){
if (link.classList.contains("active")) {
link.classList.remove("active");
link.classList.add("active");
}}));
}
Thank you!
Instead of onload you can listen to hashchange event instead to achieve this like:
window.addEventListener("hashchange", () => {
let hash = window.location.hash;
if (hash) {
let linkClass = document.querySelectorAll(".nav-link");
linkClass.forEach(x => x.classList.remove("active"))
document.querySelector('a[href="' + hash + '"]').classList.add("active");
}
});
So, whenever the url hash will change, it will remove the active class from all the links using:
linkClass.forEach(x => x.classList.remove("active"))
and then it will search for the link having that hash and add the active class to that link only using:
document.querySelector('a[href="' + hash + '"]').classList.add("active");
Working Demo:
window.addEventListener("hashchange", () => {
let hash = window.location.hash;
if (hash) {
let linkClass = document.querySelectorAll(".nav-link");
linkClass.forEach(x => x.classList.remove("active"))
document.querySelector('a[href="' + hash + '"]').classList.add("active");
}
});
#main-doc{font-family:Montserrat,sans-serif}#navbar{float:left;position:fixed;font-family:Montserrat,sans-serif;font-weight:700;min-width:230px;max-width:231px;height:100vh;background:url(https://image.freepik.com/free-vector/elegant-white-texture-background_23-2148431731.jpg);margin-top:-10px;margin-left:-10px;margin-right:40px;margin-bottom:25px;border:1px solid #000}#navbar header{padding:14px;font-size:1.8em;text-align:center;border:1px solid #000}#navbar a{display:block;color:#000;text-decoration:none;padding:15px;font-size:1.1em;text-align:center;border:1px solid #000;border-top:0}.main-section header{margin-left:30px;font-family:Notable,sans-serif;font-size:1.4rem}.main-section ul li{list-style-type:none;font-size:1.3em;padding-bottom:6px}.main-section{margin-left:230px;margin-right:50px;padding-top:20px}#main-doc{padding-bottom:60px}code{font-size:1rem;font-family:Montserrat,sans-serif}.active{color:orange!important;background-color:#00f!important}#media only screen and (max-width:425px){#navbar{max-width:425px;min-width:200px;position:relative;width:100vw;height:auto}.nav-link{margin-top:0;width:100vw}.main-section{margin-left:5px;margin-right:10px;padding-top:20px}.main-section ul{padding-left:5px}.navbar a{padding:0}}
<style>
#import url('https://fonts.googleapis.com/css2?family=Montserrat&family=Notable&display=swap');
#import url('https://fonts.googleapis.com/css2?family=Montserrat:wght#700&display=swap');
</style>
<!-- font-family: 'Montserrat', sans-serif;
font-family: 'Notable', sans-serif; -->
<nav id="navbar">
<header style="color: #FFDF01 ;background: url(https://img.freepik.com/free-photo/blue-with-vignette-marble-texture-background-with-copy-space_23-2148327728.jpg?size=626&ext=jpg)">Common Sharks</header>
<a class="nav-link" href="#About_Sharks" id="aboutSharks">About Sharks</a>
<a class="nav-link" href="#The_Great_White">The Great White</a>
<a class="nav-link" href="#Oceanic_White_Tip">Oceanic White Tip</a>
<a class="nav-link" href="#Bull_Shark">Bull Shark</a>
<a class="nav-link" href="#Tiger_Shark">Tiger Shark</a>
</nav>
<main id="main-doc">
<section class='main-section' id="About_Sharks">
<header>About Sharks</header>
</br>
<ul><span style="font-size: 2.1em; margin-left: 5px;">B</span>efore we can talk about the most deadly sharks in the world, there are a few interesting facts that will help you understand sharks as a species better.</br>
</br>
<li>Sharks do not have bones</li>
<p>Sharks use their gills to filter oxygen from the water. They are a special type of fish known <i>Elasmobranch</i>, which translates into: </br>fish made of cartilaginous tissues—the clear gristly stuff that your ears and nose tip are made of. This
category also includes rays, sawfish, and skates. Their cartilaginous skeletons are much lighter than true bone and their large livers are full of low-density oils, both helping them to be buoyant. </p>
<p>Even though sharks don't have bones, they still can fossilize. As most sharks age, they deposit calcium salts in their skeletal cartilage to strengthen it. The dried jaws of a shark appear and feel heavy and solid; much like bone. These same minerals
allow most shark skeletal systems to fossilize quite nicely. The teeth have enamel so they show up in the fossil record too.</p>
</br>
<li>Most sharks have good eyesight</li>
<p>Most sharks can see well in dark lighted areas, have fantastic night vision, and can see colors. The back of sharks’ eyeballs have a reflective layer of tissue called a tapetum. This helps sharks see extremely well with little light.</p>
<br><br>
<li>Sharks have special electroreceptor organs</li>
<p>Sharks have small black spots near the nose, eyes, and mouth. These spots are the <i>ampullae of Lorenzini</i> – special electroreceptor organs that allow the shark to sense electromagnetic fields and temperature shifts in the ocean.</p>
<br>
<li>Shark skin feels similar to sandpaper</li>
<p>Shark skin feels exactly like sandpaper because it is made up of tiny teeth-like structures called placoid scales, also known as dermal denticles. These scales point towards the tail and help reduce friction from surrounding water when the shark
swims.
</p>
<br>
<li>Sharks can go into a trance</li>
<p>When you flip a shark upside down they go into a trance like state called tonic immobility. This is the reason why you often see sawfish flipped over when our scientists are working on them in the water.</p>
</br>
<li>Sharks have been around a very long time</li>
<p>Based on fossil scales found in Australia and the United States, scientists hypothesize sharks first appeared in the ocean around 455 million years ago.</p>
<br>
<li>Scientists age sharks by counting the rings on their vertebrae</li>
<p><code>Vertebrae contain concentric pairs of opaque and translucent bands. Band pairs are counted like rings on a tree and then scientists assign an age to the shark based on the count. Thus, if the vertebrae has 10 band pairs, it is assumed to be 10 years old. Recent studies, however, have shown that this assumption is not always correct. Researchers must therefore study each species and size class to determine how often the band pairs are deposited because the deposition rate may change over time. Determining the actual rate that the bands are deposited is called <i>validation</i>.</code></p>
<br>
<li>Blue sharks are really blue</li>
<p><code>The blue shark displays a brilliant blue color on the upper portion of its body and is normally snowy white beneath. The mako and porbeagle sharks also exhibit a blue coloration, but it is not nearly as brilliant as that of a blue shark. In life, most sharks are brown, olive, or grayish.</code></p>
<br>
<li>Each whale shark’s spot pattern is unique as a fingerprint</li>
<p>Whale sharks are the biggest fish in the ocean. They can grow to 12.2 meters and weigh as much as 40 tons by some estimates! Basking sharks are the world's second largest fish, growing as long as 32 feet and weighing more than five tons.</p>
<br>
<li>Some species of sharks have a spiracle that allows them to pull water into their respiratory system while at rest</li>
<p>Most sharks have to keep swimming to pump water over their gills A shark's spiracle is located just behind the eyes which supplies oxygen directly to the shark's eyes and brain. Bottom dwelling sharks, like angel sharks and nurse sharks, use this
extra respiratory organ to breathe while at rest on the seafloor. It is also used for respiration when the shark's mouth is used for eating.</p>
<br>
<li>Not all sharks have the same teeth</li>
<p>
Mako sharks have very pointed teeth, while white sharks have triangular, serrated teeth. Each leave a unique, tell-tale mark on their prey. A sandbar shark will have around 35,000 teeth over the course of its lifetime! </p>
<br>
<li>Different shark species reproduce in different ways</li>
<p>
Sharks exhibit a great diversity in their reproductive modes. There are oviparous (egg-laying) species and <i>viviparous</i> (live-bearing) species. Oviparous species lay eggs that develop and hatch outside the mother's body with no parental care
after the eggs are laid.</p>
</section>
<section class='main-section' id="The_Great_White">
<header>The Great White</header>
<ul>
The legendary great white shark is far more fearsome in our imaginations than in reality. As scientific research on these elusive predators increases, their image as mindless killing machines is beginning to fade.
</br>
</br>
<li>Shark Attacks</li>
Of the <i><b>100-plus</b></i> annual shark attacks worldwide, fully one-third to one-half are attributable to great whites. However, most of these are not fatal, and new research finds that great whites, who are naturally curious, are "sample biting"
then releasing their victims rather than preying on humans. It's not a terribly comforting distinction, but it does indicate that humans are not actually on the great white's menu.
</br>
</br>
<li>Characteristics</li>
Great whites are the largest predatory fish on Earth. They grow to an average of 15 feet in length, though specimens exceeding 20 feet and weighing up to 5,000 pounds have been recorded. They have slate-gray upper bodies to blend in with the rocky coastal
sea floor, but get their name from their universally white underbellies. They are streamlined, torpedo-shaped swimmers with powerful tails that can propel them through the water at speeds of up to 15 miles per hour. They can even leave the water
completely, breaching like whales when attacking prey from underneath.
</br>
</br>
<li>Hunting Adaptations</li>
Highly adapted predators, their mouths are lined with up to 300 serrated, triangular teeth arranged in several rows, and they have an exceptional sense of smell to detect prey. They even have organs that can sense the tiny electromagnetic fields generated
by animals. Their main prey items include sea lions, seals, small toothed whales, and even sea turtles, and carrion.
</br>
</br>
<li>Population</li>
</code>Found in cool, coastal waters throughout the world, there is no reliable data on the great white's population. However, scientists agree that their number are decreasing precipitously due to overfishing and accidental catching in gill nets, among
other factors, and they are considered a vulnerable species.</code>
</ul>
</section>
<section class='main-section' id="Oceanic_White_Tip">
<header>Oceanic White Tip</header>
<ul>
</br>
<li>Characteristics</li>
This is an active, almost fearless shark also associated with human attacks. MarineBio considers this shark the most potentially dangerous after great whites, tiger, and bull sharks, especially for open-ocean divers. This species is likely responsible
for open-ocean attacks following air or sea disasters.
</br>
</br>
<li>Behavior</li>
Oceanic whitetips can be very aggressive and unpredictable in the presence of potential prey. Sold commercially fresh, frozen, smoked, and dried-salted for human consumption; hides for leather, fins for shark fin soup, liver oil for vitamins, and processed
into fishmeal.
</br>
This species is a widespread and common large pelagic shark of warm oceanic waters. It presumably has a low reproductive capacity, but is extremely abundant and wide-ranging and is subject to fishery pressure as a common bycatch species with tuna and
other pelagic species. This bycatch is reportedly either inadequately reported or unrecorded. The fins are highly prized in trade although the carcass is often discarded. Fishery pressure is likely to persist, if not increase in future, and the
impact of this fishing pressure is presently unknown.
</br>
</br>
<li>Population</li>
<code>The oceanic whitetip shark, <i>Carcharhinus longimanus</i>, is listed as Critically Endangered.</code>
</ul>
</section>
<section class='main-section' id="Bull_Shark">
<header>Bull Shark</header>
<ul>
Bull sharks are aggressive, common, and usually live near high-population areas like tropical shorelines. They are not bothered by brackish and freshwater, and even venture far inland via rivers and tributaries.
</br>
</br>
<li>Human Encounters</li>
Because of these characteristics, many experts consider bull sharks to be the most dangerous sharks in the world. Historically, they are joined by their more famous cousins, great whites and tiger sharks, as the three species most likely to attack humans.
</br>
</br>
<li>Characteristics</li>
Bull sharks get their name from their short, blunt snout, as well as their pugnacious disposition and a tendency to head-butt their prey before attacking. They are medium-size sharks, with thick, stout bodies and long pectoral fins. They are gray on top
and white below, and the fins have dark tips, particularly on young bull sharks.
</br>
</br>
<li>Hunting</li>
They are found cruising the shallow, warm waters of all the world’s oceans. Fast, agile predators, they will eat almost anything they see, including fish, dolphins, and even other sharks. Humans are not, per se, on their menus. However, they frequent
the turbid waters of estuaries and bays, and often attack people inadvertently or out of curiosity.
</br>
</br>
<li>Threats to Survival</li>
<code>Bull sharks are fished widely for their meat, hides, and oils, and their numbers are likely shrinking. One study has found that their average lengths have declined significantly over the past few decades.</code>
</ul>
</section>
<section class='main-section' id="Tiger_Shark">
<header>Tiger Shark</header>
<ul>
Tiger sharks are named for the dark, vertical stripes found mainly on juveniles. As these sharks mature, the lines begin to fade and almost disappear.
</br>
</br>
<li>Shark Attacks</li>
These large, blunt-nosed predators have a duly earned reputation as man-eaters. They are second only to great whites in attacking people. But because they have a near completely undiscerning palate, they are not likely to swim away after biting a human,
as great whites frequently do.
</br>
</br>
<li>Hunting</li>
They are consummate scavengers, with excellent senses of sight and smell and a nearly limitless menu of diet items. They have sharp, highly serrated teeth and powerful jaws that allow them to crack the shells of sea turtles and clams. The stomach contents
of captured tiger sharks have included stingrays, sea snakes, seals, birds, squids, and even license plates and old tires.
</br>
</br>
<li>Population</li>
Tiger sharks are common in tropical and sub-tropical waters throughout the world. Large specimens can grow to as much as 20 to 25 feet in length and weigh more than 1,900 pounds.
</br>
</br>
<li>Threats to Survival</li>
<code>They are heavily harvested for their fins, skin, and flesh, and their livers contain high levels of vitamin A, which is processed into vitamin oil. They have extremely low repopulation rates, and therefore may be highly susceptible to fishing pressure. They are listed as near threatened throughout their range.</code>
</ul>
</section>
</main>
First problem I found is that in your if loop :
if (link.classList.contains("active")) {
link.classList.remove("active");
link.classList.add("active");
}
.. only triggers on an element that already has the "active" class you want it to add, so it's not doing anything right now. If we take your existing if loop to iterate through the other and remove the active class from them, then we can safely add the active class to the link that was clicked:
window.onload = afterClick;
function afterClick() {
let linkClass = document.querySelectorAll(".nav-link");
// Add eventListener
linkClass.forEach((originalLink) =>
originalLink.addEventListener("click", function () {
let linkElems = document.querySelectorAll(".nav-link");
// Clear "active class from the same links"
linkElems.forEach((linkElem)=>{
if (linkElem.classList.contains("active")) {
linkElem.classList.remove("active");
}
});
//add the |"active" class to the originally clicked elem
originalLink.classList.add("active");
})
);
}
Hope it helps! :)
I have written a class with methods to extract and process text from html. The html file contains three articles. Each in a 'text' tag. The 'getArticles' method extracts all the text elements and creates an object. Then, the 'getTexts' method is supposed to take the text from the object and render it to html. BUT it just keeps skipping the text from the article in the middle, starting with 'Set in Australia...'. I have tried to remove another article from the html and then the missing article appeared, but it just wont include all three articles together. Help?
DOM = {
output1: document.querySelector('.output1')
};
class TextAnalyzer {
getArticles = (out) => {
this.articles = document.getElementsByTagName("text");
}
getText = (key) => {
return this.articles[key];
}
getTexts = (out) => {
const keys = Object.keys(this.articles);
console.log(keys);
keys.forEach(key => {
console.log(this.articles[key])
out.appendChild(this.articles[key])
})
}
showArticles = () => console.log(this.articles);
}
const analysis = new TextAnalyzer();
analysis.getArticles();
analysis.showArticles();
analysis.getTexts(DOM.output1);
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<section>
<doc>
<docno> LA010189-0001 </docno>
<docid> 1 </docid>
<date>
<p>
January 1, 1989, Sunday, Home Edition
</p>
</date>
<section>
<p>
Book Review; Page 1; Book Review Desk
</p>
</section>
<length>
<p>
1206 words
</p>
</length>
<headline>
<p>
NEW FALLOUT FROM CHERNOBYL;
</p>
<p>
THE SOCIAL IMPACT OF THE CHERNOBYL DISASTER BY DAVID R. MARPLES (ST. MARTIN'S
PRESS: $35, CLOTH; $14.95, PAPER; 316 PP., ILLUSTRATED; 0-312-02432-0)
</p>
</headline>
<byline>
<p>
By James E. Oberg , Oberg, a space engineer in Houston, is the author of
Uncovering Soviet Disasters: Exploring the Limits of Glasnost (Random House).
</p>
</byline>
<text>
<p>
The onset of the new Gorbachev policy of glasnost, commonly mistranslated as
openness but closer in connotation to candor or publicizing, has complicated
the task of Soviet secret-keepers and has allowed substantial new Western
insights into Soviet society. David R. Marples' new book, his second on the
Chernobyl accident of April 26, 1986, is a shining example of the best type of
non-Soviet analysis into topics that only recently were absolutely taboo in
Moscow official circles.
</p>
<p>
The author, a British-educated historian and economist, is a research associate
with the Canadian Institute of Ukrainian Studies at the University of Alberta,
and the academic style of the book is undisguised. However, its intended
audience is the general public, and anyone interested in nuclear power, or
Soviet economy and society, or human drama, or just plain sleuthing state
secrets, will find hitherto unpublished revelations and explanations of the
event and its continuing aftermath.
</p>
<p>
The effects of Chernobyl reverberated throughout so many facets of Soviet
society that a continuous coherent narrative is probably impossible. Marples
discusses half a dozen major themes arranged in a fairly arbitrary order (as
indicated by the frequent and helpful cross references throughout the text) and
succeeds in mapping out his main themes. The personal interests of each reader
determine which of the sections may be deemed too detailed and which too
sketchy, but considering the need for such a comprehensive overview, the levels
are generally appropriate.
</p>
<p>
The book is, on the one hand, not a light read, and an executive summary might
have been possible in a quarter the length. But, on the other, so many of the
judgments depend on a subtle interpretation of a multitude of sources that the
author is obligated to present the raw data for the reader's inspection. The
modular nature of the book also allows a reader to skip, browse, and revisit
earlier sections, aided by a convenient internal organization and a thorough
index.
</p>
<p>
First in the world's attention, and in the text, is a discussion of the human
victims of the accident. The official tally is 31 (only about 20 names have
ever been released), but Marples suspects there were other short-term radiation
victims. A large number of unnecessary late-term abortions were also performed
on local women, and by rights those unborn babies count as casualties.
Widespread "radiophobia" led to restricted diets which created malnourishment
and subsequent disease in thousands of people. The tens of thousands of people
taking part in cleanup operations were never included in official totals of
those exposed. Since the book went to press, Soviet military sources have
referred to at least one death in the actual reactor entombment program.
</p>
<p>
But the greatest toll is likely to occur with the delayed deaths. Here, Marples
encounters for the first time the soon familiar theme of official Soviet
myth-making around the event: Reality is twisted to serve state policy
objectives, which include calming an alarmed public with assurances that all is
well when it isn't.
</p>
<p>
And thus is born what he properly labels the "myth of Chernobyl," the official
line that the disaster provided a test that Soviet society passed with honor.
"In the Soviet view," he writes, "it was first and foremost a victory, a story
with an ending, and an ending that was triumphant."
</p>
<p>
Thus, when sober Western medical estimates placed the future "excess cancer
deaths" at several tens of thousands, both in the Soviet Union and in Europe (a
few tenths of a percent elevation of the natural cancer rate), the Soviets
reacted furiously. The estimates are branded "nonsense" and the estimators are
dismissed as "panic mongers" promulgating "anti-Soviet venom."
</p>
<p>
Subsequently the author addresses themes of environmental impact, economic and
political repercussions, public images, and the recovery operations. Along the
way, Marples provides a damning list of examples in which Soviet officials
attempted to retreat behind old-style cover-ups and outright lies. False
information was issued on radiation levels, on subsequent accidents at the
site, on contamination levels of the Kiev water supply, on severe discipline
against non-volunteer cleanup personnel, on reactor entombment schedules and on
operator training levels.
</p>
<p>
A severe 1986-1987 countrywide electrical power shortage was officially denied
although it was real enough to compel the restart of three Chernobyl reactors
in explicit violation of Soviet safety regulations. Design deficiencies of the
Chernobyl-style reactors were downplayed and human errors were declared to be
the primary culprit.
</p>
<p>
Ultimately, observes the author, "It is ironic that in an era of openness,
Chernobyl may have been both the pioneer of glasnost under Gorbachev and then
subsequently its first casualty." He ultimately concludes, "Aspects of the
disaster . . . have rarely been dealt with thoroughly or even honestly by
Soviet sources." Hence the need for this book, a need which is admirably
fulfilled despite the many remaining mysteries and uncertainties.
</p>
<p>
The July, 1987, trial of reactor personnel marked a full circle of disclosure.
Journalists were allowed into the pre-scripted first and last days, but the
weeklong deliberative sessions were held in secret and no word of their
substance has ever been released.
</p>
<p>
The propaganda purpose of the trial and surrounding official publicity, he
maintains, had one goal: "To divert culpability from the party hierarchy, in
Kiev and especially in Moscow." This is precisely the theme I have also
encountered in my own investigations of aerospace accidents of the past. Where
individual human failings led to catastrophe, a sanitized story may eventually
be released, but where Kremlin policy led to disaster (such as the Nedelin
catastrophe of 1960 or the Soyuz-1 disaster in 1967), the entire event remains
absolutely off limits to glasnost.
</p>
<p>
The closing blow-by-blow description of the nuclear power debate presages a
dramatic event which occurred too recently for inclusion in this first edition.
Viktor Legasov, tagged by the author as one of the country's two leading
pro-nuclear advocates, actually was sinking into private despair over the poor
implementation of safety standards. In the end, he made his final and most
eloquent testimony to this despair on the second anniversary of the accident,
by committing suicide. For several weeks the Soviets tried to sit on the
circumstances of his "tragic death," even issuing official non-explanations
which asserted that the death was not due to medical effects of radiation.
Finally, crusading journalist Vladimir Gubarev, with access to Legasov's
notebooks, broke the story in Pravda. Readers of this book will come to know
these and other characters so well that the suicide fits right into the "big
picture" of the catastrophe's social impacts.
</p>
<p>
For an author to so accurately describe a social milieu that subsequent
unpredictable events only enhance his insights is testimony to the highest
quality of scholarship. Readers of Marples' book will rarely be surprised as
the Chernobyl catastrophe's consequences continue to unfold in the future.
</p>
</text>
<graphic>
<p>
Photo, Chernobyl Then and Now :Photographs of the damaged reactor taken before
the construction of its concrete "sarcophagus" are, for obvious reasons, aerial
photographs. Left, an artist's reconstruction of the reactor as it would have
looked from the ground before the sarcophagus was in place. The point of view
is the same as that of an official Soviet photograph, right, taken as the
entombment neared completion.
</p>
</graphic>
<type>
<p>
Book Review; Main Story
</p>
</type>
</doc>
<doc>
<docno> LA010189-0013 </docno>
<docid> 31 </docid>
<date>
<p>
January 1, 1989, Sunday, Home Edition
</p>
</date>
<section>
<p>
Book Review; Page 10; Book Review Desk
</p>
</section>
<length>
<p>
146 words
</p>
</length>
<headline>
<p>
CURRENT PAPERBACKS: WAITING FOR CHILDHOOD BY SUMNER LOCKE ELLIOTT (PERENNIAL
LIBRARY/ HARPER & ROW: $7.95)
</p>
</headline>
<byline>
<p>
By ELENA BRUNET
</p>
</byline>
<text>
<p>
Set in Australia at the turn of the 20th Century, "Waiting for Childhood" is
the story of seven children left to cope for themselves after their parents
die. Their father, The Rev. William Lord, expires at the breakfast table one
morning. After the family leaves for a ramshackle house owned by a wealthy
cousin, the mother loses her mind and then her life in an accident.
</p>
<p>
The eldest daughter, Lily, takes charge of the entire household, as Jess
becomes a favorite of her rich cousin Jackie and watches her rival for Jackie's
affections fall fatally from a mountaintop.
</p>
<p>
These characters, "all talented, all deeply human, (are) all so beautifully
realized that by the end of the novel we identify with them to the point of
heartbreak," Carolyn See wrote in these pages. " 'Waiting for Childhood'
manages to be at once terribly melancholy and extraordinarily exhilarating."
</p>
</text>
<type>
<p>
Column; Book Review
</p>
</type>
</doc>
<doc>
<docno> LA010189-0032 </docno>
<docid> 74 </docid>
<date>
<p>
January 1, 1989, Sunday, Home Edition
</p>
</date>
<section>
<p>
Business; Part 4; Page 3; Column 1; Financial Desk
</p>
</section>
<length>
<p>
1299 words
</p>
</length>
<headline>
<p>
VIEWPOINTS;
</p>
<p>
'89 WISH LIST: PROTECTION, TAXES AND PEACE;
</p>
<p>
SOCIAL BENEFITS, DEFICIT REDUCTION ARE TOP PRIORITIES FOR THE NEW YEAR
</p>
</headline>
<text>
<p>
What changes would you like to see in business practices and the workplace this
year? How can business leaders and economic policy-makers improve the economy
and the world in general in 1989? The Times ran these questions by people in
various walks of life, and here are some of their answers:
</p>
<p>
</p>
<p>
Muriel Siebert, head of the Muriel Siebert & Co. discount brokerage in New
York, and first female member of the New York Stock Exchange:
</p>
<p>
"I would like to see certain business practices regulated. I think that the
leveraged buyouts show the greed of people at their worst. . . . The LBOs are
bypassing the purpose of the capital-raising system. I think that to the extent
that people were stockholders in these companies . . . they should be allowed
to continue to have some kind of share in the profits (after the leveraged
buyouts) because these moves were done while they were stockholders.
</p>
<p>
"Must greed be the creed? I would like to see that also rolled over to our
defense contractors. I am pro defense. I believe in a strong country because
people mistake gentility for weakness. If (contractors) cheat on defense
contracts, I don't see why they don't go to jail. . . . I just feel that if you
are a major defense contractor, you owe a fiduciary responsibility to this
country because defense expenditures are putting a pretty big toll on the
country."
</p>
<p>
Andrew Brimmer, former member of the Federal Reserve Board and head of a
Washington economics consulting firm:
</p>
<p>
"My leading wish is that the nation deal with the federal budget deficit. I
would like to see a substantial reduction in 1989 and extending over the next
three years. I would strongly recommend that we raise taxes. There should be
some moderation in the level of government expenditures, but the real problem
is the lag in revenue.
</p>
<p>
"I also would like to see more done for education by business. The kind of
education I'm talking about is at the elementary and secondary level.
Businesses are already contributing to colleges. Businesses should do likewise
for elementary and secondary schools. Business people can play a role as
counselors and teachers. A firm might make available an engineer or
mathematician to go into schools and teach. Business should do more to offer
on-the-job training for unskilled, or limited-skills, people, perhaps through a
(lower) learning wage. We would give business tax credits to do this."
</p>
<p>
William R. Robertson, executive secretary of the Los Angeles County Federation
of Labor, AFL-CIO:
</p>
<p>
"I would like to see a change in philosophy by the incoming President relating
to labor relations and providing for fairness in our (labor) organizing efforts
and contract negotiations. . . .
</p>
<p>
"I would also like to see some protection for workers losing their jobs because
of mergers. It is a national disgrace. In too many mergers, the workers are the
ones that suffer and the country as well. Something should be done to correct
it. . . .
</p>
<p>
"And, finally, this Administration should face reality in resolving the
astronomical deficit."
</p>
<p>
Steven D. Lydenberg, an associate with the "socially responsible" investment
firm of Franklin Research & Development:
</p>
<p>
"There is an increasing interest around the country in social investing. People
want to know not just the financial implications of making a commitment in a
company, but also the social implication. That information is not very easy to
come by.
</p>
<p>
"So, if at the end of '89 corporations were disclosing in a uniform way their
yield figures, their charitable contribution figures, the numbers of women and
minorities in top management and board directors, their attitude on a number of
comparable social issues, I would be very happy."
</p>
<p>
Frank Borman, chairman of Patlex Corp. of Chatsworth, former astronaut and
former chairman of Eastern Airlines:
</p>
<p>
"We should begin to move toward taxing consumption -- a value-added tax. This
is quite controversial as Al Ullman (Oregon Democrat and former chairman of the
House Ways and Means Committee, who was defeated in 1988 after advocating a
value-added tax) will tell you. But this taxing system is needed. It would
certainly help our exports. Almost all of Europe is under the value-added
taxing system. Also, it may encourage saving instead of consumption. One of the
ways you discourage consumption is to tax it."
</p>
<p>
Michael Harrington, co-chair of Democratic Socialists of America and author of
"The Other America" and "The New American Poverty":
</p>
<p>
"I hope Secretary of State Baker will build on the basic insights of former
Treasury Secretary Baker (James Baker, former treasury secretary, was nominated
by President-elect Bush to be Secretary of State) that a settlement of Third
World debt is in the self-interest of America, opening up markets for business
and labor. But then the new Baker will have to go far beyond the old, since
Latin America now owes more than it did in 1982 when the crisis officially
began, and several countries, including Argentina and Brazil, may see democracy
subverted if current trends persist.
</p>
<p>
"At home, the nation must recognize that we can't waste young people, and
particularly minorities and women, on illiteracy, unemployment and unproductive
low-wage work. We must invest mightily in education, training and job
generation."
</p>
<p>
Alan Bromberg, a securities law expert and professor at Southern Methodist
University:
</p>
<p>
"There are several things I would like most to see changed in the economy and
business practices. One, more concentration by business and government, both
here and abroad, on . . . the facilitation of international trade and
investment. This would require wider horizons for business people . . . and
more effort by government to reduce and ultimately eliminate all kinds of
restrictions on the movement of products.
</p>
<p>
"Two, I would like to see a national consensus developed, preferably in the
form of federal legislation, on corporate takeovers and buyouts that would
recognize the efficiencies and benefits they bring as well as the dislocations
and hardships they can cause. This would involve tax policies and labor polices
and limitations on the ability of states to Balkanize corporate law by
different anti-takeover statutes everywhere. (There also should be) some kind
of limitation on management self-entrenchment and self-enrichment.
</p>
<p>
"I think we could use a lot of clarification of the securities laws. I think
the courts have done a good job of saying what insider trading is. The kind of
issues that are most difficult are what really is parking (of stock)? How much
cooperation or similar action by different individuals or different groups of
individuals makes it collaboration? These issues haven't been well resolved. .
. .
</p>
<p>
Peter Bahouth, executive director of Greenpeace in Washington:
</p>
<p>
"People now view threats to human security less in terms of political threats
and more in environmental and economic terms. So for my wish list, I would ask
first that we deal with the issue of the greenhouse effect. We better develop
some alternative views in mass transportation and cut subsidies to reflect the
true cost of fossil fuels in terms of pollution, along with the actual economic
cost of development. Then, we could put more money into research and
development of wind and solar energy.
</p>
<p>
"(Also on my wish list is) peace on earth. If we want peace on earth, we have
to start looking seriously at the fact that we are making more and more
weapons, and in a process which endangers the health of American people. . . .
Production plants have been proven to have released into the air and water
radioactivity and toxic chemicals."
</p>
<p>
"Also, it would be nice if we could learn that the rain forest affects all of
us. We need to preserve it. And we would like the tuna industry to stop killing
dolphins."
</p>
</text>
<graphic>
<p>
Drawing, JILL BANASHEK / for The Times
</p>
</graphic>
</doc>
</section>
<section>
<h2>Raw Text</h2>
<div class="output1">
</div>
</section>
<script src="app.js"></script>
</body>
</html>
It happens because the order of this.articles is changing every time you use appendChild because this.articles is not an array but an HTML Collection.
DOM = {
output1: document.querySelector('.output1')
};
class TextAnalyzer {
getArticles = (out) => {
this.articles = document.getElementsByTagName("text");
}
getText = (key) => {
return this.articles[key];
}
getTexts = (out) => {
for (let i = 0; i < 5; i++) {
console.log(this.articles)
out.appendChild(this.articles[i])
}
}
showArticles = () => console.log(this.articles);
}
const analysis = new TextAnalyzer();
analysis.getArticles();
analysis.getTexts(DOM.output1);
body {
background: white
}
<text>article 0</text>
<text>article 1</text>
<text>article 2</text>
<text>article 3</text>
<text>article 4</text>
<h2>Raw Text</h2>
<div class="output1">
</div>
You can solve this by create an array from html collection (i.e. change this line):
getArticles = (out) => {
this.articles = [...document.getElementsByTagName("text")];
}
DOM = {
output1: document.querySelector('.output1')
};
class TextAnalyzer {
getArticles = (out) => {
this.articles = [...document.getElementsByTagName("text")];
}
getText = (key) => {
return this.articles[key];
}
getTexts = (out) => {
const keys = Object.keys(this.articles);
console.log(keys);
keys.forEach(key => {
console.log(this.articles[key])
out.appendChild(this.articles[key])
})
}
showArticles = () => console.log(this.articles);
}
const analysis = new TextAnalyzer();
analysis.getArticles();
analysis.showArticles();
analysis.getTexts(DOM.output1);
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<section>
<doc>
<docno> LA010189-0001 </docno>
<docid> 1 </docid>
<date>
<p>
January 1, 1989, Sunday, Home Edition
</p>
</date>
<section>
<p>
Book Review; Page 1; Book Review Desk
</p>
</section>
<length>
<p>
1206 words
</p>
</length>
<headline>
<p>
NEW FALLOUT FROM CHERNOBYL;
</p>
<p>
THE SOCIAL IMPACT OF THE CHERNOBYL DISASTER BY DAVID R. MARPLES (ST. MARTIN'S
PRESS: $35, CLOTH; $14.95, PAPER; 316 PP., ILLUSTRATED; 0-312-02432-0)
</p>
</headline>
<byline>
<p>
By James E. Oberg , Oberg, a space engineer in Houston, is the author of
Uncovering Soviet Disasters: Exploring the Limits of Glasnost (Random House).
</p>
</byline>
<text>
<p>
The onset of the new Gorbachev policy of glasnost, commonly mistranslated as
openness but closer in connotation to candor or publicizing, has complicated
the task of Soviet secret-keepers and has allowed substantial new Western
insights into Soviet society. David R. Marples' new book, his second on the
Chernobyl accident of April 26, 1986, is a shining example of the best type of
non-Soviet analysis into topics that only recently were absolutely taboo in
Moscow official circles.
</p>
<p>
The author, a British-educated historian and economist, is a research associate
with the Canadian Institute of Ukrainian Studies at the University of Alberta,
and the academic style of the book is undisguised. However, its intended
audience is the general public, and anyone interested in nuclear power, or
Soviet economy and society, or human drama, or just plain sleuthing state
secrets, will find hitherto unpublished revelations and explanations of the
event and its continuing aftermath.
</p>
<p>
The effects of Chernobyl reverberated throughout so many facets of Soviet
society that a continuous coherent narrative is probably impossible. Marples
discusses half a dozen major themes arranged in a fairly arbitrary order (as
indicated by the frequent and helpful cross references throughout the text) and
succeeds in mapping out his main themes. The personal interests of each reader
determine which of the sections may be deemed too detailed and which too
sketchy, but considering the need for such a comprehensive overview, the levels
are generally appropriate.
</p>
<p>
The book is, on the one hand, not a light read, and an executive summary might
have been possible in a quarter the length. But, on the other, so many of the
judgments depend on a subtle interpretation of a multitude of sources that the
author is obligated to present the raw data for the reader's inspection. The
modular nature of the book also allows a reader to skip, browse, and revisit
earlier sections, aided by a convenient internal organization and a thorough
index.
</p>
<p>
First in the world's attention, and in the text, is a discussion of the human
victims of the accident. The official tally is 31 (only about 20 names have
ever been released), but Marples suspects there were other short-term radiation
victims. A large number of unnecessary late-term abortions were also performed
on local women, and by rights those unborn babies count as casualties.
Widespread "radiophobia" led to restricted diets which created malnourishment
and subsequent disease in thousands of people. The tens of thousands of people
taking part in cleanup operations were never included in official totals of
those exposed. Since the book went to press, Soviet military sources have
referred to at least one death in the actual reactor entombment program.
</p>
<p>
But the greatest toll is likely to occur with the delayed deaths. Here, Marples
encounters for the first time the soon familiar theme of official Soviet
myth-making around the event: Reality is twisted to serve state policy
objectives, which include calming an alarmed public with assurances that all is
well when it isn't.
</p>
<p>
And thus is born what he properly labels the "myth of Chernobyl," the official
line that the disaster provided a test that Soviet society passed with honor.
"In the Soviet view," he writes, "it was first and foremost a victory, a story
with an ending, and an ending that was triumphant."
</p>
<p>
Thus, when sober Western medical estimates placed the future "excess cancer
deaths" at several tens of thousands, both in the Soviet Union and in Europe (a
few tenths of a percent elevation of the natural cancer rate), the Soviets
reacted furiously. The estimates are branded "nonsense" and the estimators are
dismissed as "panic mongers" promulgating "anti-Soviet venom."
</p>
<p>
Subsequently the author addresses themes of environmental impact, economic and
political repercussions, public images, and the recovery operations. Along the
way, Marples provides a damning list of examples in which Soviet officials
attempted to retreat behind old-style cover-ups and outright lies. False
information was issued on radiation levels, on subsequent accidents at the
site, on contamination levels of the Kiev water supply, on severe discipline
against non-volunteer cleanup personnel, on reactor entombment schedules and on
operator training levels.
</p>
<p>
A severe 1986-1987 countrywide electrical power shortage was officially denied
although it was real enough to compel the restart of three Chernobyl reactors
in explicit violation of Soviet safety regulations. Design deficiencies of the
Chernobyl-style reactors were downplayed and human errors were declared to be
the primary culprit.
</p>
<p>
Ultimately, observes the author, "It is ironic that in an era of openness,
Chernobyl may have been both the pioneer of glasnost under Gorbachev and then
subsequently its first casualty." He ultimately concludes, "Aspects of the
disaster . . . have rarely been dealt with thoroughly or even honestly by
Soviet sources." Hence the need for this book, a need which is admirably
fulfilled despite the many remaining mysteries and uncertainties.
</p>
<p>
The July, 1987, trial of reactor personnel marked a full circle of disclosure.
Journalists were allowed into the pre-scripted first and last days, but the
weeklong deliberative sessions were held in secret and no word of their
substance has ever been released.
</p>
<p>
The propaganda purpose of the trial and surrounding official publicity, he
maintains, had one goal: "To divert culpability from the party hierarchy, in
Kiev and especially in Moscow." This is precisely the theme I have also
encountered in my own investigations of aerospace accidents of the past. Where
individual human failings led to catastrophe, a sanitized story may eventually
be released, but where Kremlin policy led to disaster (such as the Nedelin
catastrophe of 1960 or the Soyuz-1 disaster in 1967), the entire event remains
absolutely off limits to glasnost.
</p>
<p>
The closing blow-by-blow description of the nuclear power debate presages a
dramatic event which occurred too recently for inclusion in this first edition.
Viktor Legasov, tagged by the author as one of the country's two leading
pro-nuclear advocates, actually was sinking into private despair over the poor
implementation of safety standards. In the end, he made his final and most
eloquent testimony to this despair on the second anniversary of the accident,
by committing suicide. For several weeks the Soviets tried to sit on the
circumstances of his "tragic death," even issuing official non-explanations
which asserted that the death was not due to medical effects of radiation.
Finally, crusading journalist Vladimir Gubarev, with access to Legasov's
notebooks, broke the story in Pravda. Readers of this book will come to know
these and other characters so well that the suicide fits right into the "big
picture" of the catastrophe's social impacts.
</p>
<p>
For an author to so accurately describe a social milieu that subsequent
unpredictable events only enhance his insights is testimony to the highest
quality of scholarship. Readers of Marples' book will rarely be surprised as
the Chernobyl catastrophe's consequences continue to unfold in the future.
</p>
</text>
<graphic>
<p>
Photo, Chernobyl Then and Now :Photographs of the damaged reactor taken before
the construction of its concrete "sarcophagus" are, for obvious reasons, aerial
photographs. Left, an artist's reconstruction of the reactor as it would have
looked from the ground before the sarcophagus was in place. The point of view
is the same as that of an official Soviet photograph, right, taken as the
entombment neared completion.
</p>
</graphic>
<type>
<p>
Book Review; Main Story
</p>
</type>
</doc>
<doc>
<docno> LA010189-0013 </docno>
<docid> 31 </docid>
<date>
<p>
January 1, 1989, Sunday, Home Edition
</p>
</date>
<section>
<p>
Book Review; Page 10; Book Review Desk
</p>
</section>
<length>
<p>
146 words
</p>
</length>
<headline>
<p>
CURRENT PAPERBACKS: WAITING FOR CHILDHOOD BY SUMNER LOCKE ELLIOTT (PERENNIAL
LIBRARY/ HARPER & ROW: $7.95)
</p>
</headline>
<byline>
<p>
By ELENA BRUNET
</p>
</byline>
<text>
<p>
Set in Australia at the turn of the 20th Century, "Waiting for Childhood" is
the story of seven children left to cope for themselves after their parents
die. Their father, The Rev. William Lord, expires at the breakfast table one
morning. After the family leaves for a ramshackle house owned by a wealthy
cousin, the mother loses her mind and then her life in an accident.
</p>
<p>
The eldest daughter, Lily, takes charge of the entire household, as Jess
becomes a favorite of her rich cousin Jackie and watches her rival for Jackie's
affections fall fatally from a mountaintop.
</p>
<p>
These characters, "all talented, all deeply human, (are) all so beautifully
realized that by the end of the novel we identify with them to the point of
heartbreak," Carolyn See wrote in these pages. " 'Waiting for Childhood'
manages to be at once terribly melancholy and extraordinarily exhilarating."
</p>
</text>
<type>
<p>
Column; Book Review
</p>
</type>
</doc>
<doc>
<docno> LA010189-0032 </docno>
<docid> 74 </docid>
<date>
<p>
January 1, 1989, Sunday, Home Edition
</p>
</date>
<section>
<p>
Business; Part 4; Page 3; Column 1; Financial Desk
</p>
</section>
<length>
<p>
1299 words
</p>
</length>
<headline>
<p>
VIEWPOINTS;
</p>
<p>
'89 WISH LIST: PROTECTION, TAXES AND PEACE;
</p>
<p>
SOCIAL BENEFITS, DEFICIT REDUCTION ARE TOP PRIORITIES FOR THE NEW YEAR
</p>
</headline>
<text>
<p>
What changes would you like to see in business practices and the workplace this
year? How can business leaders and economic policy-makers improve the economy
and the world in general in 1989? The Times ran these questions by people in
various walks of life, and here are some of their answers:
</p>
<p>
</p>
<p>
Muriel Siebert, head of the Muriel Siebert & Co. discount brokerage in New
York, and first female member of the New York Stock Exchange:
</p>
<p>
"I would like to see certain business practices regulated. I think that the
leveraged buyouts show the greed of people at their worst. . . . The LBOs are
bypassing the purpose of the capital-raising system. I think that to the extent
that people were stockholders in these companies . . . they should be allowed
to continue to have some kind of share in the profits (after the leveraged
buyouts) because these moves were done while they were stockholders.
</p>
<p>
"Must greed be the creed? I would like to see that also rolled over to our
defense contractors. I am pro defense. I believe in a strong country because
people mistake gentility for weakness. If (contractors) cheat on defense
contracts, I don't see why they don't go to jail. . . . I just feel that if you
are a major defense contractor, you owe a fiduciary responsibility to this
country because defense expenditures are putting a pretty big toll on the
country."
</p>
<p>
Andrew Brimmer, former member of the Federal Reserve Board and head of a
Washington economics consulting firm:
</p>
<p>
"My leading wish is that the nation deal with the federal budget deficit. I
would like to see a substantial reduction in 1989 and extending over the next
three years. I would strongly recommend that we raise taxes. There should be
some moderation in the level of government expenditures, but the real problem
is the lag in revenue.
</p>
<p>
"I also would like to see more done for education by business. The kind of
education I'm talking about is at the elementary and secondary level.
Businesses are already contributing to colleges. Businesses should do likewise
for elementary and secondary schools. Business people can play a role as
counselors and teachers. A firm might make available an engineer or
mathematician to go into schools and teach. Business should do more to offer
on-the-job training for unskilled, or limited-skills, people, perhaps through a
(lower) learning wage. We would give business tax credits to do this."
</p>
<p>
William R. Robertson, executive secretary of the Los Angeles County Federation
of Labor, AFL-CIO:
</p>
<p>
"I would like to see a change in philosophy by the incoming President relating
to labor relations and providing for fairness in our (labor) organizing efforts
and contract negotiations. . . .
</p>
<p>
"I would also like to see some protection for workers losing their jobs because
of mergers. It is a national disgrace. In too many mergers, the workers are the
ones that suffer and the country as well. Something should be done to correct
it. . . .
</p>
<p>
"And, finally, this Administration should face reality in resolving the
astronomical deficit."
</p>
<p>
Steven D. Lydenberg, an associate with the "socially responsible" investment
firm of Franklin Research & Development:
</p>
<p>
"There is an increasing interest around the country in social investing. People
want to know not just the financial implications of making a commitment in a
company, but also the social implication. That information is not very easy to
come by.
</p>
<p>
"So, if at the end of '89 corporations were disclosing in a uniform way their
yield figures, their charitable contribution figures, the numbers of women and
minorities in top management and board directors, their attitude on a number of
comparable social issues, I would be very happy."
</p>
<p>
Frank Borman, chairman of Patlex Corp. of Chatsworth, former astronaut and
former chairman of Eastern Airlines:
</p>
<p>
"We should begin to move toward taxing consumption -- a value-added tax. This
is quite controversial as Al Ullman (Oregon Democrat and former chairman of the
House Ways and Means Committee, who was defeated in 1988 after advocating a
value-added tax) will tell you. But this taxing system is needed. It would
certainly help our exports. Almost all of Europe is under the value-added
taxing system. Also, it may encourage saving instead of consumption. One of the
ways you discourage consumption is to tax it."
</p>
<p>
Michael Harrington, co-chair of Democratic Socialists of America and author of
"The Other America" and "The New American Poverty":
</p>
<p>
"I hope Secretary of State Baker will build on the basic insights of former
Treasury Secretary Baker (James Baker, former treasury secretary, was nominated
by President-elect Bush to be Secretary of State) that a settlement of Third
World debt is in the self-interest of America, opening up markets for business
and labor. But then the new Baker will have to go far beyond the old, since
Latin America now owes more than it did in 1982 when the crisis officially
began, and several countries, including Argentina and Brazil, may see democracy
subverted if current trends persist.
</p>
<p>
"At home, the nation must recognize that we can't waste young people, and
particularly minorities and women, on illiteracy, unemployment and unproductive
low-wage work. We must invest mightily in education, training and job
generation."
</p>
<p>
Alan Bromberg, a securities law expert and professor at Southern Methodist
University:
</p>
<p>
"There are several things I would like most to see changed in the economy and
business practices. One, more concentration by business and government, both
here and abroad, on . . . the facilitation of international trade and
investment. This would require wider horizons for business people . . . and
more effort by government to reduce and ultimately eliminate all kinds of
restrictions on the movement of products.
</p>
<p>
"Two, I would like to see a national consensus developed, preferably in the
form of federal legislation, on corporate takeovers and buyouts that would
recognize the efficiencies and benefits they bring as well as the dislocations
and hardships they can cause. This would involve tax policies and labor polices
and limitations on the ability of states to Balkanize corporate law by
different anti-takeover statutes everywhere. (There also should be) some kind
of limitation on management self-entrenchment and self-enrichment.
</p>
<p>
"I think we could use a lot of clarification of the securities laws. I think
the courts have done a good job of saying what insider trading is. The kind of
issues that are most difficult are what really is parking (of stock)? How much
cooperation or similar action by different individuals or different groups of
individuals makes it collaboration? These issues haven't been well resolved. .
. .
</p>
<p>
Peter Bahouth, executive director of Greenpeace in Washington:
</p>
<p>
"People now view threats to human security less in terms of political threats
and more in environmental and economic terms. So for my wish list, I would ask
first that we deal with the issue of the greenhouse effect. We better develop
some alternative views in mass transportation and cut subsidies to reflect the
true cost of fossil fuels in terms of pollution, along with the actual economic
cost of development. Then, we could put more money into research and
development of wind and solar energy.
</p>
<p>
"(Also on my wish list is) peace on earth. If we want peace on earth, we have
to start looking seriously at the fact that we are making more and more
weapons, and in a process which endangers the health of American people. . . .
Production plants have been proven to have released into the air and water
radioactivity and toxic chemicals."
</p>
<p>
"Also, it would be nice if we could learn that the rain forest affects all of
us. We need to preserve it. And we would like the tuna industry to stop killing
dolphins."
</p>
</text>
<graphic>
<p>
Drawing, JILL BANASHEK / for The Times
</p>
</graphic>
</doc>
</section>
<section>
<h2>Raw Text</h2>
<div class="output1">
</div>
</section>
<script src="app.js"></script>
</body>
</html>
I have this bit of HTML. I want to insert in the div class content between 2nd and 3rd paragraph tag. I saw .insertAfter() and .insertBefore(). How to do this in plain vanilla JS?
<div class="content">
<div class="lead-image"><img src="/rf/Image-621x414/LiveMint/Period2/2017/10/13/Photos/Processed/bhart-kvpG--621x414#LiveMint.JPG" alt="Vodafone-Idea combine is ahead by a sizeable margin. Photo: Pradeep Gaur/Mint" class="img-responsive">
<div class="img-caption">In a few quarters, Airtel will end up as a clear market leader in terms of revenue market share, even though currently, the Vodafone-Idea combine is ahead by a sizeable margin. Photo: Pradeep Gaur/Mint</div>
</div>
<p xmlns:fn="http://www.w3.org/2005/xpath-functions" class="A5l">After Telenor ASA decided to hand over its India mobile business to Bharti Airtel Ltd for free, the Tata group has done the same. In the June quarter, revenues of these companies together stood at Rs3,202 crore, or nearly $2 billion on an annualized basis. Sure, since Tata’s non-mobile businesses, such as broadband, are being retained, the actual revenue that could potentially accrue to Airtel could be lower.</p>
<p>Still, even using conservative estimates, the Tatas are transferring at least a $1 billion business to Airtel for free. Telenor’s annualized revenues stood at $606 million in the June quarter. </p>
<p>In fact, the Tatas have gone a step further compared to Telenor. For the latter, Airtel agreed to take over outstanding spectrum payments, other operational contracts such as tower leases and employees. But the deal with the Tatas is even sweeter; it will take over only a portion of outstanding spectrum payments and it’s not clear whether operational contracts and employees are part of the deal.</p>
<p>The simple reason Airtel is able to strike such deals is that it is the only buyer in the market. Vodafone India Ltd and Idea Cellular Ltd have enough on their plate with their own merger, and the last thing they would want to engage with is the integration of another telco. Reliance Jio Infocomm Ltd, after having spent Rs2 trillion already in building its network, appears self-sufficient. Of course, these are also distress sales, given the high-cash burn at these companies. For sellers, therefore, one big hope is if Airtel evinces some interest. The only other option is to wind down the business, which entails far higher costs. </p>
<p>A Tata Sons executive told <i>Mint</i> the cost of winding down the business would have been about Rs8,000 crore higher than the current arrangement. Knowing this well, Airtel has stayed shy of rushing into deals, and has waited till sellers agree to its terms.</p>
<div class="mobile-ad">
<div id="div-gpt-ad-1492578481854-0" style="height: 250px; width: 300px; display: none;">
<script>
googletag.cmd.push(function() {
googletag.display('div-gpt-ad-1492578481854-0');
});
</script>
<div id="google_ads_iframe_/3106570/LM_WAP_Story_300x250_Top_0__container__" style="border: 0pt none;">
<iframe id="google_ads_iframe_/3106570/LM_WAP_Story_300x250_Top_0" title="3rd party ad content" name="google_ads_iframe_/3106570/LM_WAP_Story_300x250_Top_0" width="300" height="250" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" srcdoc="" style="border: 0px; vertical-align: bottom;"></iframe>
</div>
</div>
</div>
<p></p>
<p>This puts it in an enviable position; such takeovers help grow market share as well as help plug gaps in its spectrum portfolio at a fairly low cost. In addition, with Vodafone and Idea busy with the merger process, and given the uncertainty among their employees, Airtel can grab market share from its large rivals as well.</p>
<p></p>
<div id="chart-box">
<img class="img-responsive" src="/r/LiveMint/Period2/2017/10/13/Photos/Processed/w_m2m_infratel-kvpG--414x621#LiveMint.jpg" title="">
<div class="zoom_icon"><a class="zoom-icon" href="/r/LiveMint/Period2/2017/10/13/Photos/Processed/w_m2m_infratel-kvpG--414x621#LiveMint.jpg" title="">Click here for enlarge</a></div>
</div>
<link href="/r/PortalConfig/LiveMint/static_content/css/v2/lightbox.css" type="text/css" rel="stylesheet">
<p></p>
<p>However, when things improve—hopefully with Jio’s approval for higher tariffs—Airtel can be expected to be in a fairly strong position as it gobbles up small telcos one after another and also gains share from other companies.</p>
<div class="story-meta"><span>First Published: </span>Fri, Oct 13 2017. 07 16 AM IST
<div class="story-tags">Topics: Airtel Tata Teleservices Airtel Tata Tele acquisition Airtel acquisitions Telenor ASA </div>
</div>
</div>
I am trying to do it in the best possible way. The class name is unique and I can then iterate through. What is the right way?
var myfirstcontent = document.getElementsByClassName('content')[0];
//find paragraphs
var ps = myfirstcontent.getElementsByTagName("p");
// Create a new, plain <div> element
var newdiv1 = document.createElement("div");
// put content etc in the div here...
// Get a reference to the paragraph we want to insert the new div after
var p2 = ps[1];
// Get a reference to the parent element
var parent = p2.parentNode;
// insert after
parent.insertBefore(newdiv1 , p2.nextSibling);
Note if there is no nextSibling it just gets appended to the parent node at the end as that returns null.
How about this?
var div = document.querySelector('div.content');
var thirdP = document.querySelectorAll('div.content > p')[2];
var newDiv = document.createElement('div');
newDiv.innerHTML = '***';
div.insertBefore(newDiv, thirdP);
I am a bit stumped on this. I just started working with javascript and I am having a little trouble getting this to work. Basically I have links within paragraphs that expand when clicked using javascript. However, I would like to add an effect to this expansion such as fading or scrolling. Previously, I have only added effects to div classes but this isn't a div. Anyway here is my code thanks!
Javascript:
function reveal(a){
var e=document.getElementById(a);
if(!e) return true;
if(e.style.display=="none"){
e.style.display="inline"
} else {
e.style.display="none"
}
return true;
}
html:
<title>Project Star in a Jar</title>
<link rel="stylesheet" type="text/css" href="/../default.css"/>
<script type="text/javascript" src="/jscript/function.js"></script>
</head>
<link rel="shortcut icon" href= "/../images/favicon.png"/>
<link rel="icon" href="/../images/favicon.png" type="image/x-icon">
<body>
<div class="wrapOverall">
<div class="header">
<div class="logo">
<img src="/../images/starJar.png" href="index.php" style="width:100px;height:100px">
<div class="moto">
<h1> Project Star in a Jar</h1>
</div>
</div>
<div class="nav_main">
<ul>
<li>Home</li>
<li>Tutorial</li>
<li>Videos</li>
<li>Other Resources</li>
</ul>
</div>
</div>
<div class="sideContent">
<div class="sideTitle">
<h3>Table of Contents</h3>
</div>
<div class="sideLinks">
<ul>
<li>i. Introduction</li>
<li>1. What is Fusion?</li>
<li>2. Hazards and Safety</li>
<li>3. Vacuum Chamber</li>
<li>4. Inner Grid</li>
<li>5. Outer Grid</li>
<li>6. Vacuum System</li>
<li>7. Electrical System</li>
<li>8. Achieving Fusion </li>
<li>9. Putting it all Together</li>
<li>10. Great, Now What?</li>
</ul>
</div>
</div>
<div class="Content">
<div class="contentTitle">
<h1>Star in a Jar - A How-To Guide</h1>
<h2>Introduction</h3>
</div>
<div class="contentText">
<!--Paragraph One-->
<p>
Why would anyone want to build a <q>star in a jar</q>? Is it because they want to feel like a mad scientist? Because they want to impress their friends or peers? Although these are all possible reasons, the main reason why people have been building and researching these incredible devices is because quite frankly, we are running out of energy solutions. If we don't have a working solution in the next 20-50 years, we either won't have energy or the little energy we produce will be outrageously expensive. The energy that we consume is almost directly matched with the human exponential growth model and we simply cannot be sustained with conventional energy production methods. The more people that are aware or interested in this technology, the faster we will be able to develop fusion based energy solutions.
</p>
<!--Paragraph Two-->
<p>
Since this is an advanced topic and this writing will use highly technical lexis, I will write in such a way as to target multiple audiences. I understand that some of you reading this are doing so because you are planning on building or already built a fusion device and are looking for more useful information to further develop and experiment with your device. On the other hand, some of you may be reading this from a purely academic standpoint and have nor the intention or means to build such a device. That is perfectly fine! If the former, and you are familiar with the terms and already have an understanding of the concepts in this text, then you can read it without expanding the text for a better tailored experience. However, if the latter, and you are unfamiliar with the terms of this field, I have developed the writing on the site to be dynamic and interactive. Every word or phrase you see that is in orange, can be expanded into an explanation when clicked. Try it out with the following phrase!
What is Tritium?.
<a id="para1" style="display:none">
(Tritium is a radioactive isotope of hydrogen with one proton and two neutrons)
</a>
I implemented this feature because I realize that this writing will be read by many different audiences with their own unique purposes for reading. As the writer, I strive to make this writing dynamic to fit their needs independently without compromising convince or enjoyment. Although the main purpose of this tutorial is to give a detailed analysis of the device and its workings in a tutorial based format, it is also to educate and address the needs and wants of the reader and hopefully, in the process raise awareness to a phenomenal technology that will change the world.
</p>
<!--Content Image-->
<div class="contentImage">
<img src="/../images/intro1.jpg" style="width:300px;height:300px">
</div>
<!--Paragraph Three-->
<p>
This tutorial is not going over any new exotic technology. The particular machine described uses very basic principles of classical physics and has been around since the mid 60's. Depending on the materials you have on hand, your results will vary. I can guarantee at the bare minimum, you will have a working demo fusor if you follow this tutorial. A demo fusor essentially does everything a normal fusor does, with the exception that no fusion of atoms is occurring. It is called demo because it is typically much easier to build and operate safely and is used to demonstrate the operation of a fusor. The picture on the right is of a preliminary run of my first demo fusor.
</p>
<!--Paragraph Four-->
<p>
<b>WARNING:</b>
</p>
<!--Paragraph Five-->
<p>
Before we begin the tutorial, I would like to point out that although this machine is of a very simple design and can be built from essentially junk, does NOT mean it is by any means safe. The minimum operating voltage for most demo fusors are 2-6kv and 10-30kv for fusors achieving fusion reactions. High voltages are extremely dangerous and the high voltage supplies discussed can and most likely will kill you if an accident occurs or you misuse them. The Hazards and Safety section will go into more detail about the all possible hazards presented and how to deal with them accordingly.
</p>
<!--Paragraph Six-->
<p>
Understand that this is a dangerous experiment that if done improperly, has the potential to harm or kill you or others who do not follow proper safety measures. I do not take any responsibility for death, injury, property damage, potential outrageous energy bills, blown breakers, glowing in the dark, fecaled pants, becoming a green hulk when angry, or failure of experimenter to hold sufficient health, liability or property insurance.
</p>
</div>
<div class="contentSelector">
>>
</div>
</div>
</div>
<div class="footer">
<a>
Copyright # 2014 Project Star In A Jar. All Rights Reserved.<br>
Website and Content Created by Joshua Hess <a target="blank" href="http://www.youtube.com/s28400"><u>(s28400)</u></a>
</a>
</div>
</body>
Your question isn't entirely clear... but it seems like you're just asking how to do animations in JavaScript.
Here's some code you can use for fading in (taken from http://youmightnotneedjquery.com/):
function fadeIn(el) {
el.style.opacity = 0;
var last = +new Date();
var tick = function() {
el.style.opacity = +el.style.opacity + (new Date() - last) / 400;
last = +new Date();
if (+el.style.opacity < 1) {
(window.requestAnimationFrame && requestAnimationFrame(tick)) || setTimeout(tick, 16)
}
};
tick();
}
fadeIn(el);
or, if you are using jQuery (not sure if the tag was listed correctly or not), a similar function has already been made for fading in the library:
$(el).fadeIn();
Do note that a fade in in this way requires you setting opacity values (not display values).
You also mentioned in your question "Previously, I have only added effects to div classes but this isn't a div". Classes are just one way to implement CSS styles, if you've used CSS animations before, the same CSS animation will work for nearly any element (there are cases where they won't), you just have to give that element a class with the animation you want. As this wasn't asking for CSS in specific, you can take a look here for more information: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Using_CSS_animations or at this question for fade in specifically: Using CSS for fade-in effect on page load