View Full Version : How to trigger click on css child (envolving ID)

03-19-2012, 08:24 PM

I'm working on a usability issue on a website. I have a jquery accordion slider, each slide has a link to a category. Now what happens is that when I go to the category page by clicking on a slider, when the page loads, the sliders always opens the first slide. For example, if I click on the third slide, I would like that slide to be open when the page loads.

This is similar to the :current I believe. I think to solve what I need I must trigger a click on the third slide that third slide page opens.

I know I need a reference for a condition, so I have ID'd my body through this php code were it gets the page name from the url into variable $page and then into do body's ID:


$page = $_SERVER['REQUEST_URI'];

$page = str_replace("/","",$page);

$page = str_replace(".php","",$page);

$page = str_replace("?s=","",$page);

$page = $page ? $page : 'default'


<body id="<?php echo $page ?>">

Now I've been trying through Javascript to get the variable from php and trigger a click on the slide of the category it is opening:

<script type="text/javascript">

var bodyid = "<? $page ?>";

if (bodyid == "energy") {

$("document").ready(function() {
setTimeout(function() {
$("ul#accordion li:second-child).trigger('click');



This is not working and I don't really know what's wrong and how to solve or search for help.

Does anyone understand what I'm trying to do here? Thank you.

03-19-2012, 10:06 PM
you should probably take it to dynamic drive forums. They have an accordion script that allows what you're looking for and will help make adjustments if needed.