I am brand new to Jquery and have run into something that if answered will help greatly in the future. I have 2 very simple questions I am using codeigniter, HTML5 and all php pages as well.
I have a menu 'aside' with 4-5 sections that I want to be able to close to save space. So I am using 2 simple slideToggle scripts.
$("a").click(function () {
$('#cat').slideToggle('slow', function() {
})
});
and
$("button").click(function () {
$('#dog').slideToggle('slow', function() {
})
});
The problem is, if I use button on both, both scripts operate even though I am requesting the script to run on 2 different ID's ( I know the dog and cat thing is silly, I just threw them in to see if a fake id would work and it did)
The question is, how can I use button OR a href on both scripts to preserve my styling?
My second question is can you put multiple scripts on a .js file for inclusion and how would you do it? Does each get script tags or some other kind of separator?
Thanks for helping, these are my first two scripts. At least they work :)
<div class="menu">
<h2>News Links</h2>
<a href="#">Display</a>
<!--
if I use "button" here, both scripts run on tandem
-->
<script>
$("a").click(function () {
$('#cat').slideToggle('slow', function() {
})
});
benchmark->mark('links_start');
$this->db->order_by('id', 'DESC');
$this->db->limit('10');
$query = $this->db->get('links');
foreach ($query->result() as $row)
{
echo "link \" title=\"$row->title\" target=\"_blank\">$row->name ";
}
$this->benchmark->mark('links_end');
?>
</ul>
</div>
</div>
<div class="menu">
<h2>Archives</h2>
<button>Display</button> <!--if I use "a" here, both scripts run on tandem
-->
<script>
$("button").click(function () {
$('#dog').slideToggle('slow', function() {
})
});
</script>
<div id="dog">
<?php
$this->db->order_by('id', 'DESC');
$where = "publish";
$this->db->where('status', $where);
$this->db->select('id, title', FALSE);
$this->db->select('DATE_FORMAT(date, "%b %D %Y")AS date');
$this->db->from('posts');
$query = $this->db->get();
foreach ($query->result() as $row)
aelement, and the second will run when you click anybutton. That probably isn't what you want.