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 8933439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:32:12+00:00 2026-06-15T09:32:12+00:00

another challenge – this is more for cleaner looking code than a how do

  • 0

another challenge – this is more for cleaner looking code than a “how do I”. Here’s the idea.

<section id="projector" data-start-at="7">....</section>

in JS

$('#projector').projector_slider({'startFrom' : parseInt( REF TO DATA-START-AT )});

I am calling a custom function on a HTML element. Simple. The function has an option called “startFrom” indicated by an INT. The INT is stored in an attribute attached to the HTML element. What I want is to NOT have to find $('#projector') in the DOM again.

Is there a way I can get a reference to the Projector inside the function call – something like $(this).attr('data-start-at)?

Obv I can solve this by looking up the element again and accessing it directly, Im asking the question in the hopes of learning a new ‘this’ reference trick while cleaning up my JS.

  • 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-15T09:32:13+00:00Added an answer on June 15, 2026 at 9:32 am

    No, you can’t. You should save $('#projector') in a var and use it:

    var projector = $('#projector');
    
    projector.projector_slider({
        startFrom: parseInt(projector.data('start-at')),
    });
    

    Notice that I use [.data()][data] instead of .attr('data-*'). The data() function is created by jQuery and is a smart way to interact with data-* attributes. For instance, if you have data-first=true and use .data('first') you will get a boolean ‘true’ and if you have data-children="['foo', 'bar']" you will get an object if you use .data('children').

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

Sidebar

Related Questions

So here's yet another 'write a query to X' challenge. I'm monitoring a number
The assignment in the Big Nerd Ranch Guide says: Silver Challenge: Another initializer Create
Am now facing an other challenge. Some parts of my html code has the
another newbie-question regarding rails and bootstrap. I am using something like this: <div class=tabbable
another sql problem of mine .. this time the reader doesn't work properly (
Ran into another challenge. I looked through some of the questions that I found
This questions somehow relates to the question when I was looking to get the
The challenge: The shortest code by character count that will generate a series of
The challenge The shortest code by character count to draw an ASCII representation of
This is a challenge for the css gurus out there. I want to show

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.