Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Docs for dropdown #41300

Open
2 tasks done
Kembreg1405 opened this issue Mar 14, 2025 · 2 comments
Open
2 tasks done

Improve Docs for dropdown #41300

Kembreg1405 opened this issue Mar 14, 2025 · 2 comments

Comments

@Kembreg1405
Copy link

Kembreg1405 commented Mar 14, 2025

Prerequisites

Proposal

This page:

https://getbootstrap.com/docs/5.0/components/dropdowns/#via-javascript

Has this code:

var dropdownElementList = [].slice.call(document.querySelectorAll('.dropdown-toggle'))
var dropdownList = dropdownElementList.map(function (dropdownToggleEl) {
  return new bootstrap.Dropdown(dropdownToggleEl)
})

I found this code difficult to understand.
I request a simple explanation on how to show a dropdown by js or jquery.
It should be id based, not class based.
To open 1 dropdown, not all dropdowns.

Something along the lines:

To open a downdown using the item id, use this:

const dropdownIns = new bootstrap.Dropdown($('#myid').parent().prev());
dropdownIns.show();

or similar.

Motivation and context

The docs example is abstruse.

@julien-deramond
Copy link
Member

The 5.3 documentation example is slighly different:

const dropdownElementList = document.querySelectorAll('.dropdown-toggle')
const dropdownList = [...dropdownElementList].map(dropdownToggleEl => new bootstrap.Dropdown(dropdownToggleEl))

Probably a little bit less difficult to understand than in 5.0. What do you think?

@Kembreg1405
Copy link
Author

Kembreg1405 commented Mar 16, 2025

Julien, Thanks for writing.
Honestly, looks complicate for something that should be very simple.

The docs still refer to a class. What if there are two dropdowns? Better to refer to an id.

Stackoverflow had this example:

const dropdownIns = new bootstrap.Dropdown($('#dropdownlistitem').parent().prev());
dropdownIns.show();

But it did not work for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants