Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9209279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:48:18+00:00 2026-06-18T00:48:18+00:00

so i implemented a bit of jQuery that basically toggles content via a slider

  • 0

so i implemented a bit of jQuery that basically toggles content via a slider that was activated by an <a> tag. now thinking about it id rather have the DIV thats holding the link be the link its self.

the jQuery that i am using is sitting in my head looks like this:

<script type="text/javascript">
function slideonlyone(thechosenone) {
 $('.systems_detail').each(function(index) {
      if ($(this).attr("id") == thechosenone) {
           $(this).slideDown(200);
      }
      else {
           $(this).slideUp(600);
      }
 });
}
</script>

i was using this as a index type box so there are several products when you click on the <a> tag that used to be an image* it would render a bit of content beneath it describing the products details:

<div class="system_box">
  <h2>BEE Scorecard database</h2>
  <p>________________</p>
  <a href="javascript:slideonlyone('sms_box');"></a>
</div>

the products details are wrapped in this div.

<div class="systems_detail" id="sms_box">
</div>

so when you click on what used to be a image* it would run the slideonlyone(‘div_id_name’) function. the function above then first closes all the other divs with the class name ‘system details’ and then opens/slides the div with the id that was passed into the slideonlyone function. that way you can toggle products details and not have them all showing at once.

note i only kept the <a> tag to show you what was in there i will be getting rid of it.

note: i had an idea of just wrapping the whole div in an <a> tag but is that good practice?

So now what i am wondering is since you need JavaScript to run onclick on a div tag how do you write it so that it still runs my slideonlyone function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:48:19+00:00Added an answer on June 18, 2026 at 12:48 am

    Using obtrusive JavaScript (i.e. inline code) as in your example, you can attach the click event handler to the div element with the onclick attribute like so:

     <div id="some-id" class="some-class" onclick="slideonlyone('sms_box');">
         ...
     </div>
    

    However, the best practice is unobtrusive JavaScript which you can easily achieve by using jQuery’s on() method or its shorthand click(). For example:

     $(document).ready( function() {
         $('.some-class').on('click', slideonlyone('sms_box'));
         // OR //
         $('.some-class').click(slideonlyone('sms_box'));
     });
    

    Inside your handler function (e.g. slideonlyone() in this case) you can reference the element that triggered the event (e.g. the div in this case) with the $(this) object. For example, if you need its ID, you can access it with $(this).attr('id').


    EDIT

    After reading your comment to @fmsf below, I see you also need to dynamically reference the target element to be toggled. As @fmsf suggests, you can add this information to the div with a data-attribute like so:

    <div id="some-id" class="some-class" data-target="sms_box">
        ...
    </div>
    

    To access the element’s data-attribute you can use the attr() method as in @fmsf’s example, but the best practice is to use jQuery’s data() method like so:

     function slideonlyone() {
         var trigger_id = $(this).attr('id'); // This would be 'some-id' in our example
         var target_id  = $(this).data('target'); // This would be 'sms_box'
         ...
     }
    

    Note how data-target is accessed with data('target'), without the data- prefix. Using data-attributes you can attach all sorts of information to an element and jQuery would automatically add them to the element’s data object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement a moving photo slider that is no jQuery ,
I'm a little bit confused about which method to use : 1- using Jquery
Evening, I'm a bit confused about why some of my jquery isn't working. Here's
I haven't implemented a search feature before and feel a bit stuck. I have
I implemented the Facebook registration on my website. Everything works fine except that suddenly
I'm working on a program that uses HTML/CSS/Javascript/JQuery for its user interface. One of
Afternoon all. Another hour, another question! I have the following bit of jquery up
I'm using Cargo Collective to host http://cargocollective.com/amytdatta/biography I have this bit of jQuery in
I have a bit of web design that I’m trying to solve with efficient
I've implemented a search box that acts as a filter. When a user clicks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.