Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
How to add a special class only to first child of auto generated list?
Hello,
I’m working on a project which requires me add special class to only the first item in an unordered list generated by <txp:upm_article_image /> tag.
I need to generate code like below:
<ul class="something">
<li class="active child">image 1</li>
<li class="child">image 1</li>
<li class="child">image 1</li>
</ul>
I’m not sure if this’s really a textpattern problem, can it be solved by javascript or anything else?
thanks for your time.
Offline
Re: How to add a special class only to first child of auto generated list?
Not sure how upm_article_image works but you might be able to do it using a variable or one of the count plugins such as mdn_count.
jquery way could be
$(".something:first-child").addClass("active");
or
$(".child:first").addClass("active");
Last edited by MattD (2012-05-16 21:54:44)
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: How to add a special class only to first child of auto generated list?
Instead of adding a class could you achieve your desired result with CSS by using a psuedo class
ul.something>:first-child
OR
li:first-child
Offline
Offline
#5 2012-05-21 10:25:15
- a7atylor
- New Member
- Registered: 2012-05-21
- Posts: 6
Re: How to add a special class only to first child of auto generated list?
You could do this using jquery:
http://api.jquery.com/first/
I often use .last() for removing the border and other styles in lists.
Offline