{"id":20485454,"url":"https://github.com/rudifa/ad-astro","last_synced_at":"2025-10-07T22:22:18.895Z","repository":{"id":262304425,"uuid":"863199272","full_name":"rudifa/ad-astro","owner":"rudifa","description":"Yet another astro site","archived":false,"fork":false,"pushed_at":"2024-12-22T20:06:57.000Z","size":2630,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-05T16:30:06.465Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Astro","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rudifa.png","metadata":{"files":{"readme":"README-DATA-ATTRIBUTES.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-25T22:19:55.000Z","updated_at":"2024-12-22T19:01:12.000Z","dependencies_parsed_at":"2024-11-11T18:35:49.114Z","dependency_job_id":"c090d7f4-4d77-4346-ac0c-3a1b840e9bdf","html_url":"https://github.com/rudifa/ad-astro","commit_stats":null,"previous_names":["rudifa/ad-astro"],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/rudifa/ad-astro","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rudifa%2Fad-astro","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rudifa%2Fad-astro/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rudifa%2Fad-astro/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rudifa%2Fad-astro/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rudifa","download_url":"https://codeload.github.com/rudifa/ad-astro/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rudifa%2Fad-astro/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270336742,"owners_count":24566794,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-13T02:00:09.904Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T16:30:35.328Z","updated_at":"2025-10-07T22:22:13.864Z","avatar_url":"https://github.com/rudifa.png","language":"Astro","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HTML custom data attributes\n\n**Rudolf Farkas**\nexplain the relations between `data-audio-file` and `button.dataset.audioFile`\n\n**Tabnine Claude 3.5 Sonnet**\n\nCertainly! The relationship between `data-audio-file` and `button.dataset.audioFile` is a key part of how HTML5 data attributes work with JavaScript. Let's break it down:\n\n1. HTML Data Attribute:\n   In the HTML (or in this case, the Astro component template), we have:\n\n   ```astro\n   \u003cbutton class='audio-button' data-audio-file={audioFile}\u003e\n   ```\n\n   Here, `data-audio-file` is a custom data attribute. The `data-` prefix is special; it allows you to store custom data on HTML elements.\n\n2. JavaScript Dataset API:\n   In the JavaScript part, we access this data using the `dataset` property:\n\n   ```javascript\n   const audioFile = button.dataset.audioFile;\n   ```\n\n3. How They Relate:\n   - When you create a data attribute like `data-audio-file` in HTML, it becomes available in JavaScript through the `dataset` object.\n   - The naming convention is transformed:\n     - The `data-` prefix is removed.\n     - Any hyphens are converted to camelCase.\n\n   So, `data-audio-file` in HTML becomes `audioFile` in `dataset`.\n\n4. Value Assignment:\n   - In the Astro component, you're setting the value dynamically:\n     ```astro\n     data-audio-file={audioFile}\n     ```\n   - This means each button will have its `data-audio-file` attribute set to the corresponding `audioFile` value from your `audioFiles` array.\n\n5. Accessing in JavaScript:\n   - When you use `button.dataset.audioFile` in your script, you're retrieving the value that was set in the HTML.\n   - This allows you to access the specific audio file path for each button when it's clicked.\n\nIn summary, `data-audio-file` in the HTML/Astro template is how you store the data, and `button.dataset.audioFile` in JavaScript is how you retrieve that data. This mechanism allows you to associate custom data with HTML elements and easily access it in your JavaScript code, creating a bridge between your markup and your script.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frudifa%2Fad-astro","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frudifa%2Fad-astro","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frudifa%2Fad-astro/lists"}