Why don’t you use CSS pseudo attributes for that.
You can simply use :first-child
and :last-child
to target first and last element for CSS styling.
Here is how you do that with CSS pseudo attributes.
div.post:last-child div.testing_imran img {
your styles for last image
}
Also FYI, your code will work too, if you want to target last image in CSS file. You don’t really need to add CSS class to image itself, but adding CSS class to div container will work fine too.
div.testing_imran.imd_last img {
your styles for last image
}
If you want to targe image in jQuery, then same rules work for jQuery too.
Related Posts:
- How to split a loop into multiple columns
- Is it necessary to reset the query after using get_posts()?
- Using the Loop to show all levels of subpages under a parent page? Halfway there
- Cleanest Way to Select Every Second Element in a Loop?
- Pagination not working on home page
- How to Change Loop to Order Posts by Views (using wp-postviews plugin)
- Get post by page name or slug
- save_post + insert_post = infinite loop
- Get ID of a page containing secondary loop in content
- Are there any scenarios where the query_posts may be used?
- ACF Repeater loops and resets – where is the reset_rows() documentation? [closed]
- Display subpages under parent page as a list within a loop
- When to use wp_reset_postdata();
- Why do themes have `while( have_posts() )` in templates like single.php?
- What is best way passing variables to theme templates and using them different places like widgets?
- Apply styling only to first page sticky posts
- Exclude category by slug for for each loop
- Related Posts loop – offset
- Too many nested wp_query loops in this hypothetical query?
- pop-up lighbox with AJAX
- Showing current subcategory
- Load comments per post on click with AJAX
- The main Loop is not starting in a custom blog template page
- WordPress Loop – Style rows of posts differently
- Generating dynamic Tabs with multiple query post loop
- How do I override part of the main loop in my child theme?
- connect last post with first post
- Custom loop with conditional statement to separate each terms
- taxonomy tags 404 to custom post types
- Breaking the loop?
- Only display videos and images in the_content() within loop
- woocommerce stored variable
- Query last updated posts (posts updated in the last 24 hours)
- A smarter way to display multiple loops inside a page template
- Publish Categories for a particular Author on a given Post
- How to print out menu names in the foreach loop?
- How do I style the first two posts of a loop
- Do I need to use The Loop on pages?
- How to get the role id from the role name?
- How do I paginate a get_posts() request inside another page loop (Paginating childpages)
- How to hook into container
- Is wp_reset_postdata() redundant after the main loop?
- While loop with bootstrap [closed]
- How to create a multidimensional array with multiple loops
- Get paged outside of loop?
- How to create custom popup in shop page on every loop products?
- Show scheduled posts in loop (but don’t link to them)?
- How to get a count of all posts in foreach loop and split into fourths
- Getting posts link in WordPress
- Loop through an array inside a class using foreach [closed]
- using wp_get_attachment_image_src in foreach loop
- Grabbed Post ID under WP loop, but still couldn’t Print Post title
- How to loop through yoast primary categories? [closed]
- How to separate posts loop in to two columns? [duplicate]
- WordPress get post thumbnail url
- query_posts clarification needed
- display post tags on single.php inside loop
- Custom content before post content
- Can’t get the previous and next posts permalink
- Adding first and last classes to three column layout in Bones boilerplate
- Modifying a Loop to Show More
- Does search.php autofilter The Loop?
- “the_excerpt” in loop just keeps repeating first post?
- wpdb inside foreach loop only returns first result – 2 other similar cases found [closed]
- Using jQuery .after inside loop
- How to check all items in a loop have post thumbnail?
- Add 2 values to post__not_in
- How to loop specific Category menu from archive page?
- How to display post tag on each post? [closed]
- How can I pass additional params to a shortcode while in a loop?
- ACF: display custom filed of CPT into the loop
- How to add “NEW” badge on latest posts or published 3 days interval
- Add all category as classes in foreach loop
- Exclude posts from loop by term
- How to avoid appending “null” in Ajax?
- Alternative layout the loop
- Why loop renders only last metabox from array? [closed]
- Show posts by tags excluding current post
- Adding options to loop
- Structure and Display Content from Multiple Pages on Single Page
- Featured posts and the loop
- How to fix pagination for custom loops?
- Thumbnail of the latest posts page
- Combining external feed into post loop
- Get last 5 days with posts
- Is there a way to target only images within the loop?
- Code to check amount of blog posts and add css
- Loop to get current parent page “content” and his children content
- Add Div IDs dynamically to CSS
- Displaying posts limit: can’t get pagination to display [duplicate]
- Show last post from multiple categories using wp_list_categories
- Load featured article once in a loop
- How to use add_action(“wpcf7_before_send_mail” outside wp loop?
- posts_nav_link() not working on index.php
- How to add custom HTML markup and classes to the_content()?
- $do_not_duplicate is not working in genesis theme
- Loop displays current page
- Error in Wordprewss loop for page template [closed]
- Tags outside the loop
- Hook in the loop after the first post