Loading...
Copy code
Close
Permalink
Close
Please tell us why you want to mark the subject as inappropriate.
(Maximum 200 characters)
Report Inappropriate
Cancel
Private Message
From :
guest
To :
Subject :
Content :
Type the characters you see in the picture below.
Send
Cancel
From :
guest
To :
Subject :
Content :
Type the characters you see in the picture below.
Send
Update
Cancel
Feedback
Email ID
Subject :
Comments :
Send
Cancel
Private Message
Type the characters you see in the picture below.
Type the characters you see in the picture below.
Attach files
Desktop
Google Docs
Each Attachment size should not exceed 1.0 MB.
Max no of attachments : 3
Loading User Profile...
guest
Response title
This is preview!
Attachments
Publish
Back to edit
Cancel
(
)
Sign In
New to this Portal? Click here to
Sign up
You can also use the below options to login
Login with Facebook
Login with Google
Login with Yahoo
jQuery
Plugins
UI
Meetups
Forum
Blog
About
Donate
All Forums
Recent Posts
Log In
Search
jQuery
Search
jQuery Forum
Move this topic
Forum :
Getting Started
Using jQuery
Using jQuery Plugins
Using jQuery UI
Developing jQuery Core
Developing jQuery Plugins
Developing jQuery UI
QUnit and Testing
About the jQuery Forum
jQuery Conferences
jQuery Mobile
Developing jQuery Mobile
Sub forum :
Move this topic
Cancel
Using jQuery
darko74
Alternative to each() in the middle of a chain when there's only one element
in
Using jQuery
•
9 years ago
An example will help:
tabContent.css('width', '0')
.css('opacity', '0')
.filter(':eq(0)')
.css('opacity', '1')
.parent()
.find('.one-tab')
.addClass('active')
.css('cursor', 'default');
Now I want to apply the parent of tabContent a width, only if a condition is true. I do this, and works, but I don't consider this is a proper way:
tabContent.css('width', '0')
.css('opacity', '0')
.filter(':eq(0)')
.css('opacity', '1')
.parent()
.each(function() {
if (/*condition is true*/) {
$(this).width(aWidth + 'px');
}
$(this)
.find('.one-tab')
.addClass('active')
.css('cursor', 'default');
});
Is there a better way instead of using each() which is actually made for loops? In this case there is only one element
1
Reply
Replies(3)
Chrazy
Re: Alternative to each() in the middle of a chain when there's only one element
9 years ago
The width method will accept a function as its value, so there you can put your if statement.
Leave a comment on Chrazy's reply
Kevin B
Re: Alternative to each() in the middle of a chain when there's only one element
9 years ago
Code for Chrazy's suggestion:
.parent().width(function(i,w){
if (/*condition*/) {
return aWidth;
}
return w;
}).find('.one-tab').etc
-- Kevin
Leave a comment on Kevin B's reply
darko74
Re: Alternative to each() in the middle of a chain when there's only one element
9 years ago
As plain as day. Thanks both of you for your replies!
Leave a comment on darko74's reply
Change topic type
Topic Type :
Discussions
Questions
Ideas
Problems
No of days :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Change topic type
Cancel
Link this topic
Provide the permalink of a topic that is related to this topic
Permalink
Save
Close
Reply to darko74's question
Top
Reply
{"z3712105":[14737000002891946,14737000002900161],"z3123152":[14737000002903280],"z2960617":[14737000002903218]}
Statistics
3
Replies
3805
Views
0
Followers
Tags
Cancel
each
chain
alternative
one element
Actions
Permalink