CodeIgniter Forums
jquery help - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: jquery help (/showthread.php?tid=26812)



jquery help - El Forum - 01-23-2010

[eluser]richzilla[/eluser]
Hi all, i know this isnt technically codeigniter, but these forums are the best for getting a sensible answer. Basically im trying to find away to highglight the current page, so for example the link in the navigation bar is highlighted when you are on that page. Ive thought of a jquery solution but it doesnt seem to be working:

I have this in my header;
Code:
[removed]
$(document).ready(function(){
    $("#nav a").each(function(){
            if($(this).attr("page_id") == <?php echo $page_id; ?>)
            {
                $(this).addClass("active");
            }
        });
});

[removed]

and in my header view:

Code:
<div id="nav">

&lt;?php echo anchor('home','Home',array('page_id' => 13)); ?&gt;
            
&lt;?php echo anchor('upgrade-and-repair','Upgrade &amp; Repair',array('page_id' => 14)); ?&gt;
            
&lt;?php echo anchor('data','Data Recovery',array('page_id' => 12)); ?&gt;
            
&lt;?php echo anchor('about','About',array('page_id' => 11)); ?&gt;
            
&lt;?php echo anchor('contact','Contact',array('page_id' => 10)); ?&gt;

</div>

any ideas where im going wrong?


jquery help - El Forum - 01-23-2010

[eluser]Dyllon[/eluser]
ID your body tags


jquery help - El Forum - 01-24-2010

[eluser]vitoco[/eluser]
Following the above advice ...

[quote author="ricardino" date="1264304340"]Hi all, i know this isnt technically codeigniter, but these forums are the best for getting a sensible answer. Basically im trying to find away to highglight the current page, so for example the link in the navigation bar is highlighted when you are on that page. Ive thought of a jquery solution but it doesnt seem to be working:

I have this in my header;
Code:
[removed]
$(document).ready(function(){
    $("#nav a#page_&lt;?php echo $page_id; ?&gt;").addClass("active");
});

[removed]

and in my header view:

Code:
<div id="nav">

&lt;?php echo anchor('home','Home',array('id' => 'page_'.13)); ?&gt;
            
&lt;?php echo anchor('upgrade-and-repair','Upgrade &amp; Repair',array('id' => 'page_'.14)); ?&gt;
            
&lt;?php echo anchor('data','Data Recovery',array('id' => 'page_'.12)); ?&gt;
            
&lt;?php echo anchor('about','About',array('id' => 'page_'.11)); ?&gt;
            
&lt;?php echo anchor('contact','Contact',array('id' => 'page_'.10)); ?&gt;

</div>
[/quote]


jquery help - El Forum - 01-24-2010

[eluser]Patrick K[/eluser]
Code:
if($(this).attr("page_id") == &lt;?php echo $page_id; ?&gt;)


page_id isn't a valid HTML attribute. I think you're using it incorrectly. for example:

Code:
<img src="sss" alt="image_name" title="this title" />

you'd .attr("alt") or .attr("title")

if you want it to work you'd have to:

Code:
<a href="" title="1" class="unique-name"></a>

var page_id = $('#unique-name").attr('title');

if (page_id == &lt;? echo $page_id; ?&gt;){
  //hilight the sonuvabitchere.
}