1

I am trying to add functionality to an already built javascript slider. I am trying to add in images of the videos that people can click to bring them to the proper video in the slide. I am trying to accomplish this with jQuery. I would like to know how to get the attribute of the divs inside of div.navBulletsWrapper. My code at the moment seems to change all the divs to rel="0" instead of getting the rel value and setting the class accordingly. Thanks for any help.

HTML:

<div class="video-thumbnail">
    <a id="video-thumbnail1">
       <img src="/_images/VideoImages/btn_FreeConsultation.png" />
    </a>
</div>

This is being created dynamically by the slider javascript:

<div class="navBulletsWrapper">
    <div class="active" rel="0"> … </div>
    <div rel="1"> … </div>
    <div rel="2"> … </div>
    <div rel="3"> … </div>
</div>

jQuery:

$(document).ready(function(){

    $('#video-thumbnail1').click(function(){
        $('div.navBulletsWrapper div').attr("rel", "0").addClass("active");
    });

});

live website in case you want to see full code: http://www.hazeltonlawgroup.com

1
  • Not sure to fully understand your question, but tell me if i am wrong, you want to select the div with the attribute rel=0 and add the class to it? Commented Sep 5, 2013 at 20:45

4 Answers 4

1

If you want to find a div according to its attribute, you have to do it with selector:

$('div.navBulletsWrapper div[rel="0"]').addClass('active') ;

If you want to remove class from the others div:

$('div.navBulletsWrapper div:not([rel="0"])').removeClass('active')
Sign up to request clarification or add additional context in comments.

1 Comment

This was actually a very good answer as it is not what I asked, but I still did need to remove instances of the class from other divs. Thank you.
1
$('div.navBulletsWrapper div').attr("rel", "0")

This sets all the child div's with attribute rel="0" .

If you looking to target that div.. then you selector should somewhat look in these lines.

$('div.navBulletsWrapper').find("[rel='0']").addClass("active");

1 Comment

there should be a . before the find function
1

With the attar method you can set and get an attribute.

el.attr('attribute',value')

set the attribute.

el.attr('attribute')

get the attribute value.

Just change your code to

$(document).ready(function(){

    $('#video-thumbnail1').click(function(){
        $('div.navBulletsWrapper div[rel='+index+']').addClass("active");
    });

});

Where index is the element which you want to add the 'active' class

Comments

0

Another way

$('div.navBulletsWrapper div').filter("[rel=0]").addClass("active");

or

$('div.navBulletsWrapper').find("div[rel=0]").addClass("active");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.