मेरे पास एक संदर्भ पृष्ठ है, लेकिन मैं इसे संपादित करना चाहता हूं। मैं उन्हें कार्य क्षेत्रों के अनुसार अलग करना चाहूंगा। उदाहरण के लिए प्रौद्योगिकी स्वास्थ्य वगैरह। मैं इसके लिए एक काम कर रहा हूं लेकिन मुझे आमतौर पर PHP में दिलचस्पी है, ये ऐसी चीजें हैं जिन्हें मैंने बहुत लंबे समय तक नहीं देखा है। मुझे जेएस पसंद नहीं है और जब तक मुझे ऐसा नहीं करना है, तब तक इसका उपयोग न करने का प्रयास करें। मेरी समस्या यह है कि एक आईडी के बाद अन्य लोग इसे छिपाने की कोशिश कर रहे हैं। लेकिन ऐसा इसलिए था कि मैं मदद नहीं कर सकता कि कैसे कॉल करूं मुझे नहीं पता कि क्या स्कैन करना है।
function gizleGoster(ID) {
var secilenID = document.getElementById(ID);
if (secilenID.style.display == "none") {
secilenID.style.display = "";
} else {
secilenID.style.display = "none";
}
}
function tumu() {
var secilenID = document.getElementById('health');
secilenID.style.display = "";
secilenID = document.getElementById('technology');
secilenID.style.display = "";
secilenID = document.getElementById('automotive');
secilenID.style.display = "";
}
<a href="#" onclick="tumu()">All</a>
<a href="#" onclick="gizleGoster('health')">Health</a>
<a href="#" onclick="gizleGoster('technology')">Technology</a>
<a href="#" onclick="gizleGoster('automotive')">Automotive</a><br>
<br>
<br>
<div id="health">health</div><br>
<div id="technology">technology </div><br>
<div id="automotive">automotive</div><br>
<div id="health">health</div><br>
1 उत्तर
यहाँ एक तरीका यह किया जा सकता है। आपको इसे अपने उपयोग के मामले में फिट करने के लिए आवश्यकतानुसार इसे ट्वीक करने की आवश्यकता हो सकती है। कृपया ध्यान दें कि मैंने आपके HTML को भी संशोधित कर दिया है।
function getIndustries() {
return document.getElementById('industries').getElementsByTagName("div");
}
function hideElement(element){
element.style.display = "none";
}
function showElement(element) {
element.style.display = "";
}
function tumu() {
var industries = getIndustries();
for(var industry of industries) {
showElement(industry);
}
}
function gizleGoster(ID) {
var industries = getIndustries();
for(var industry of industries) {
if (industry.className === ID) {
showElement(industry);
}
else {
hideElement(industry);
}
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<a href="#" onclick="tumu()">All</a>
<a href="#" onclick="gizleGoster('health')">Health</a>
<a href="#" onclick="gizleGoster('technology')">Technology</a>
<a href="#" onclick="gizleGoster('automotive')">Automotive</a><br>
<br>
<br>
<div id="industries">
<div class="health">health</div><br>
<div class="technology">technology </div><br>
<div class="automotive">automotive</div><br>
<div class="health">health</div><br>
</div>
</body>
</html>