Comments (11)
This isn't documented at the moment, but you can pass classes along using a data-class
attribute. I'm considering what to do about other data-*
attributes, but haven't landed on a solution quite yet. Can you describe your use case for needing to send these along? It might help me figure out a good solution.
from fancyselect.
I was gonna pass those data-* attributes so I can check on the selected option and the value of this attribute and change some part of the page I'm working with...
from fancyselect.
You don't need to use data attributes to check the selected option. Just check it on the select itself as per usual:
$('#my-select').val();
from fancyselect.
not the value of option itself, I use that somewhere else, I needed data-* attrs specially to specify something else than the value of option itself, you can imagine the value of an option is "iPod" and the value of data-category is "Music Player" or something like that...
thanks for the fast response
from fancyselect.
Ah, I see. Now that I'm thinking about it, there's probably no need to pass along data attributes other than data-class
anyhow, since you can just access them directly on the select:
var mySelect = $('#my-select');
mySelect.fancySelect();
var someData = mySelect.data('whatever');
Any reason that wouldn't work for your use case?
from fancyselect.
what does this going to return?
var someData = mySelect.data('whatever');
I'm asking this since the list item generated by fancySelect doesn't have the exact attributes that each option itself has
from fancyselect.
If:
<select id="mySelect" data-whatever="something">
<option>Foo</option>
</select>
Then:
var mySelect = $('#my-select');
mySelect.fancySelect();
var someData = mySelect.data('whatever');
// someData == 'something'
Exactly like using jQuery's data
normally.
from fancyselect.
you see It was my mistake if I didn't describe my problem right,
the problem is that I assign some kinda data-* attrs to 'option' elements not the 'select' element itself, just like the example: option is 'iPod' and data-cat of that specific option is 'Music Player'...
your solution returns the data attribute of select element, please tell me where I'm mistaken...
from fancyselect.
Oh, I see. I guess I misunderstood.
You could do something like this:
$('#my-select').on('change', function() {
var el = $(this),
cat = el.find('option:selected').data('cat')
});
Again, pretty similar to what you'd to do with a normal select.
EDIT: Updated with cleaner code. Also, working code.
from fancyselect.
I see, I can mange something with that,
thanks, for the time and effort
from fancyselect.
I'm going to leave this open for a bit to remind me to update the docs. Glad I could help.
from fancyselect.
Related Issues (20)
- Touch devices: show styled trigger but use browser's default UI to select an option HOT 7
- Zepto compatibility
- Question regarding click event & chaining.
- What is the best way to have 2 different select styles? HOT 2
- FancySelect not showing up on Windows Phone devices
- Minimal styles
- Links in dropdown options HOT 1
- Select not opened in iphone HOT 4
- Width Of Select Box and Dropdown Box
- Update Readme.md HOT 1
- OptGroups not supported HOT 4
- Validation On Select Box HOT 11
- A way to select a value using jquery HOT 2
- close dropdown problem HOT 1
- Add Bower and NPM Support HOT 3
- IE11 scroll Issue
- Tabbing + keydown in Firefox v50 opens native & styled dropdown's
- Filter or Hide options
- select item doesn't change in multiple select boxes
- Easily style select elements in all major browsers? How so?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fancyselect.