ARTICLE-PUBLISHER
ARTICLE-PUBLISHER
code
<!DOCTYPE html>
<html>
<head>
<title>Article Reading</title>
</head>
<body>
<h1>Article Reading</h1>
<h2>List of Articles</h2>
<ul id="article-list"></ul>
<h2>Article Details</h2>
<h3 id="article-title"></h3>
<p id="article-author"></p>
<div id="article-content"></div>
<script>
// Sample data
var articles = [
{
title: "Introduction to Python",
author: "John Doe",
content: "This is an introductory article about Python."
},
{
title: "Web Development Basics",
author: "Jane Smith",
content: "Learn the basics of web development."
},
{
title: "Data Science Techniques",
author: "Alice Johnson",
content: "Explore various data science techniques."
}
];
// Populate article list
var articleList = document.getElementById("article-list");
articles.forEach(function(article) {
var listItem = document.createElement("li");
var link = document.createElement("a");
link.href = "#";
link.textContent = article.title;
link.addEventListener("click", function() {
displayArticle(article);
});
listItem.appendChild(link);
articleList.appendChild(listItem);
});
// Display article details
function displayArticle(article) {
var title = document.getElementById("article-title");
var author = document.getElementById("article-author");
var content = document.getElementById("article-content");
title.textContent = article.title;
author.textContent = "Author: " + article.author;
content.textContent = article.content;
}
</script>
</body>
</html>
Comments
Post a Comment