<a href="#link">Click</a> <details id="link"> <summary>Text...</summary> blablabla </details> How to make that when you click on the link, the open attribute for the details tag is added?
Click
How to make ...">Text...
blablabla
<a href="#link">Click</a> <details id="link"> <summary>Text...</summary> blablabla </details> How to make that when you click on the link, the open attribute for the details tag is added?
$('a').on('click', function() { const id = $(this).attr('href'); $(id).attr('open', function(index, attr) { return attr == 'open' ? null : 'open'; }); }) <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a href="#link">Click</a> <details id="link"> <summary>Text...</summary> blablabla </details> I wrote both the attribute and the class specifically, since I doubt that you need the attribute
$(document).ready(function(){ $("a[href='#link']").on("click", function(){ $("#link").attr("open"); // Attribute $("#link[open]").css("display", "block") // $("#link").toggleClass("open"); class }) }) <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a href="#link">Click</a> <details id="link"> <summary>Text...</summary> blablabla </details> html - I suspected that he was already ready to css - Pavel Igorevich<details id="link" open> - BrimBamBoSource: https://ru.stackoverflow.com/questions/894511/
All Articles