Free tutorials & notes in Hindi & English · Clean code examples 🧰 मुफ़्त PDF और फ़ोटो टूल्स →
🚀 Days 11–15 – Pro Skills और Projects  ·  दिन 11

दिन 11: details, dialog, progress और data-*

⏱ 80 min📶 Intermediate🎯 100% self-study
दिन 11 / 15

✅ आज आप सीखेंगे

  • details/summary से FAQ accordions (शून्य JS)
  • dialog और popover से popups
  • progress, meter, output और mark
  • template से दोबारा इस्तेमाल होने वाला markup
  • data-* attributes में अतिरिक्त data

🏢 असली दुनिया में

Sharma Sweets को एक FAQ section (“क्या यह eggless है?”, “क्या delivery करते हैं?”), Diwali offer popup, bulk orders के लिए delivery-progress bar और price व weight याद रखने वाले product cards चाहिए। कई developers बड़ी JavaScript library उठा लेते हैं – आधुनिक HTML ज़्यादातर काम ख़ुद कर देता है।

details और summary: शून्य JavaScript वाला accordion

HTML
<style>details{border:1px solid #fcd9c8;border-radius:8px;padding:8px 12px;margin:6px 0;font-family:system-ui}
summary{cursor:pointer;font-weight:600;color:#9a3412}</style>
<details open>
  <summary>Are your sweets eggless?</summary>
  <p>Yes. All our mithai is 100% vegetarian and eggless, made in pure desi ghee.</p>
</details>
<details name="faq">
  <summary>Do you deliver outside Jaipur?</summary>
  <p>We ship dry sweets (kaju katli, soan papdi) across India in 3–5 days.</p>
</details>
<details name="faq">
  <summary>How long do they stay fresh?</summary>
  <p>Milk sweets: 2 days in the fridge. Dry sweets: up to 15 days.</p>
</details>
▶  Click a question – it opens and closes itself
💡 एक-समय-में-एक accordion

कई <details> को एक ही name दें (ऊपर के आख़िरी दो की तरह) तो browser एक समय में सिर्फ़ एक खुला रखता है – सभी आधुनिक browsers में चलता है।

dialog: सही popups

HTML
<style>dialog{border:none;border-radius:12px;padding:20px;max-width:280px;font-family:system-ui;box-shadow:0 10px 40px #0004}
dialog::backdrop{background:#0006}</style>
<button type="button" onclick="offer.showModal()">🎁 See Diwali offer</button>
<dialog id="offer" aria-labelledby="ot">
  <h2 id="ot">Diwali Special 🪔</h2>
  <p>Flat 10% off on gift boxes above ₹2,000 till 1 November.</p>
  <form method="dialog"><button>Close</button></form>
</dialog>
▶  showModal(): focus is trapped inside; Esc closes it
Featureमुफ़्त में क्या मिलता है
showModal()काला backdrop, पीछे का page inactive, focus अंदर
Esc keyDialog बंद
<form method="dialog">अंदर के buttons बिना JS logic बंद करते हैं
::backdropधुँधले background को CSS से style करें

popover: no JavaScript at all

HTML
<button popovertarget="info">ℹ️ Ingredients</button>
<div id="info" popover style="padding:12px;border-radius:8px;font-family:system-ui">
  Cashew 60%, sugar 38%, ghee 2%, silver vark.
</div>
▶  popover + popovertarget: click outside or Esc closes it

progress, meter, output, mark

HTML
<div style="font-family:system-ui">
<p>Bulk order status: <progress value="3" max="5">3 of 5</progress> 3 / 5 steps (packing)</p>
<p>Uploading photo: <progress>loading…</progress> (no value = busy)</p>
<p>Box filled: <meter min="0" max="1" low="0.3" high="0.8" optimum="1" value="0.65">65%</meter> 65%</p>
<p>Shop rating: <meter min="0" max="5" value="4.6">4.6/5</meter> 4.6 / 5</p>
<form oninput="total.value = (+kg.value) * 900">
  <label>Kaju katli kg <input id="kg" type="number" value="2" min="1" style="width:60px"></label>
  = ₹<output name="total" for="kg">1800</output>
</form>
<p>Search result: Fresh <mark>ghewar</mark> available today.</p>
</div>
▶  Live bars and a calculator – change the kg

progress

  • समय के साथ काम पूरा होना
  • Order steps, uploads, quiz progress
  • value नहीं = अनिश्चित spinner

meter

  • ज्ञात range में माप
  • Rating, storage, stock level
  • low/high/optimum रंग बदलते हैं

data-* attributes और template

HTML
<style>.card{display:inline-block;border:1px solid #ddd;border-radius:8px;padding:8px;margin:4px;font-family:system-ui;cursor:pointer}
.card[data-stock="low"]{border-color:#e34f26}</style>
<div class="card" data-name="Kaju Katli" data-price="900" data-stock="low">Kaju Katli</div>
<div class="card" data-name="Ghewar" data-price="650" data-stock="ok">Ghewar</div>
<p id="out">Click a card…</p>
<script>
document.querySelectorAll('.card').forEach(function (c) {
  c.onclick = function () { out.textContent = c.dataset.name + ': ₹' + c.dataset.price + '/kg, stock ' + c.dataset.stock; };
});
</script>
▶  data-price is read by JS as element.dataset.price; CSS can style [data-stock="low"]
HTML
<ul id="list" style="font-family:system-ui"></ul>
<template id="row"><li><b class="n"></b> – ₹<span class="p"></span>/kg</li></template>
<script>
var sweets = [['Ladoo', 500], ['Rasmalai', 700], ['Ghewar', 650]];
sweets.forEach(function (s) {
  var li = row.content.cloneNode(true);
  li.querySelector('.n').textContent = s[0];
  li.querySelector('.p').textContent = s[1];
  list.appendChild(li);
});
</script>
▶  &lt;template&gt; is invisible markup that JS copies – perfect for repeated cards
🧠 JS course के लिए यह क्यों ज़रूरी

data-* और template, HTML और JavaScript के बीच पुल हैं। JavaScript course में आप इन्हीं से पूरी Sharma Sweets cart बनाएँगे।

🏅 आज के Job Skills

✔ details/summary से FAQ accordions✔ dialog और popover से accessible popups✔ progress, meter और output से status✔ data-* में data और template से markup दोबारा

Practice tasks

🏋️ Practice – ख़ुद करें

Task 1: Home delivery का 3-सवालों वाला FAQ बनाएँ जिसमें एक समय में एक ही जवाब खुले।
Solution देखें
HTML
<details name="d" open><summary>Minimum order?</summary><p>₹500 within 5 km.</p></details>
<details name="d"><summary>Delivery time?</summary><p>Within 2 hours, 9 am – 9 pm.</p></details>
<details name="d"><summary>Payment?</summary><p>UPI, cards or cash on delivery.</p></details>
▶  Result
Task 2: “Book a tasting” button बनाएँ जो छोटे form (name, date) और Cancel button वाला modal dialog खोले।
Task 3: Loyalty card में <meter> दिखाएँ: 10 में से 7 visits पूरे।

Quick quiz

🧠 Quick Quiz – ख़ुद को जाँचें

1. कौन सा element बिना JS accordion बनाता है?
Native toggle।
2. Dialog को modal के रूप में कौन सा method खोलता है?
show() non-modal खोलता है।
3. 4.2/5 rating किससे दिखाएँ?
Range में माप।
4. data-price="900" JS में कैसे पढ़ते हैं?
dataset data-* नाम जोड़ता है।
5. <template> के अंदर का content…
Inert markup।

Interview corner

💼 Interview Corner

div वाले modal की जगह <dialog> क्यों?

showModal() वाला dialog सही role, focus प्रबंधन, Esc से बंद, inactive background और ::backdrop देता है – divs से हाथ से बनाने पर ये सब आसानी से ग़लत हो जाते हैं।

Data attributes किसलिए?

Elements पर custom, न दिखने वाला data (IDs, prices, states) रखने के लिए, जिसे JavaScript dataset से पढ़ता है और CSS attribute selectors से target करता है – बिना invalid attributes बनाए।

सारांश

  • details/summary = accordion; एक name = एक ही खुला।
  • dialog.showModal() और popover accessible popups देते हैं।
  • Tasks के लिए progress, माप के लिए meter, नतीजों के लिए output।
  • data-* अतिरिक्त data रखता है; template दोबारा उपयोग वाला markup।
➡️ आगे

Day 12: graphics और embeds – inline SVG icons, canvas drawing, और iframe से Google Maps व YouTube को सुरक्षित embed करना।

अक्सर पूछे जाने वाले प्रश्न (FAQ)

क्या details/summary SEO के लिए ठीक है?
हाँ – छिपा text भी HTML में है और index होता है। अतिरिक्त visibility के लिए FAQPage schema (Day 9) जोड़ें।
क्या अब भी JavaScript चाहिए?
साधारण toggles और popups के लिए नहीं। Cart, data लाने और जटिल logic के लिए हाँ – वही JS course है।
← HTML (15 Days)
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

अगला topicदिन 12: SVG, Canvas और iframes आपकी प्रगति: 11 / 15 (73%) · Lesson 12 / 15 आगे बढ़ें →

यह lesson कैसा लगा?

आपकी राय से हम content और बेहतर बनाते हैं।

अपना review और सुझाव लिखें (वैकल्पिक)

Review approve होने के बाद आपका नाम और शहर इसके साथ public दिख सकते हैं। Email या phone न लिखें।

▶ CodingEasily on YouTube

Video से सीखें – आसान Hindi में

चुनी हुई video: RDBMS भाग 3 – Class XI Commerce IT

▶ Channel subscribe करें