jimfog Posted August 22, 2013 Share Posted August 22, 2013 I have 2 fieldsets where they contain one input element each and with js I have set these to read only. Here is the code: http://jsfiddle.net/fiddlehunt/WJ8qU/20/ I have 2 questions. 1.WHy the hide class is not applied to the fieldsets as set by the js code and 2.How I can use the filter(if this is the correct way to do it) method so that the js code does not apply in a specific element? Meaning that the input element in one of the fieldsets can be written wile now both input elements in both fieldsets are set to read only. Link to comment Share on other sites More sharing options...
davej Posted August 22, 2013 Share Posted August 22, 2013 It is not clear to me what you are wanting this code to do. I would think that you would want the top button to toggle the visibility of the lower portion? Link to comment Share on other sites More sharing options...
jimfog Posted August 22, 2013 Author Share Posted August 22, 2013 It is not clear to me what you are wanting this code to do. I would think that you would want the top button to toggle the visibility of the lower portion? In fiddle you will see that in both fieldsets 2 inputs are contained where they are set to read only. Is there a way using the filter() method so that only one input element from that two is set to read only. The js code you see in fiddle targets all input elements within fieldsets. The code you see is a piece from the code I have locally. The whole code has more fieldsets-that is why I want to use filter, unless of course there is a better way to achieve what I want. Link to comment Share on other sites More sharing options...
dsonesuk Posted August 22, 2013 Share Posted August 22, 2013 You have not closed the second fieldset, depending on what you are looking for, you can use .not() to not target specific element of same type by using class for example, elements .gt() than specific index, or those that contain specific input names, contained in specific container there are several ways to do this. Link to comment Share on other sites More sharing options...
jimfog Posted August 22, 2013 Author Share Posted August 22, 2013 I used not() after all, thanks. Just for educational purposes though, what was wrong with filter()? Link to comment Share on other sites More sharing options...
dsonesuk Posted August 22, 2013 Share Posted August 22, 2013 Theres nothing wrong with using filter(), but its more likely better used for when you require a more complex selection of elements. Link to comment Share on other sites More sharing options...
davej Posted August 24, 2013 Share Posted August 24, 2013 Is there a performance advantage for not starting over with another selector? //$('fieldset').addClass('hide').find('input').prop('readonly', true);//$('fieldset').addClass('hide').last().find('input').prop('readonly', true);//$('fieldset').addClass('hide').children('input.service,input.price').prop('readonly', true);//$('fieldset').addClass('hide').filter('.openservices').find('input').prop('readonly', true);//$('fieldset').addClass('hide').eq(1).find('input').prop('readonly', true);$('fieldset').addClass('hide').filter('.openservices').find('input').prop('readonly', true); vs. $('fieldset').addClass('hide');$('fieldset:nth-of-type(2) > input').prop('readonly', true); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now