KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I got some help earlier regarding selectors, but I'm stuck with the following. Lets say you have a plugin like this $('#box').customplugin(); how can I get the #box as a string in the plugin? Not sure if that's the correct way of doing it, and any other solution would be great as well. Considering #box is a select dropdown, The problem I'm having is if I do the regular javascript $('#box').val(x); The correct option value gets selected, but if i try the same inside a plugin ..... this.each(function() { var $this = $(this); $this.val(x); the last code doesn't really do anything. I notice I'm having trouble targeting #box inside the plugin because it's a object and not a string... Any help would be appreciated. Thanks! Edit:: Putting in the code I'm working in for better understanding (function($){ $.fn.customSelect = function(options) { var defaults = { myClass : 'mySelect' }; var settings = $.extend({}, defaults, options); this.each(function() { // Var var $this = $(this); var thisOpts = $('option',$this); var thisSelected = $this[0].selectedIndex; var options_clone = ''; $this.hide(); options_clone += '<li rel=""><span>'+thisOpts[thisSelected].text+'</span><ul>' for (var index in thisOpts) { //Check to see if option has any text, and that the value is not undefined if(thisOpts[index].text && thisOpts[index].value != undefined) { options_clone += '<li rel="' + thisOpts[index].value + '"><span>' + thisOpts[index].text + '</span></li>' } } options_clone += '</ul></li>'; var mySelect = $('<ul class="' + settings.myClass + '">').html(opti
Tags (comma-separated)
Save Edits
Cancel