0

I have three simple buttons.

<div class="enter-btn">Enter</div>

<div class="all-btn">All</div>


<div class="category-all">
    <div class="back-btn" data-action="">Back</div>
</div>

When you click on either Enter or All, it adds a data-action value to the Back button.

$(".enter-btn").bind("click", function() {
    $(".back-btn").attr("data-action", "search-home");
});

$(".all-btn").bind("click", function() {
    $(".back-btn").attr("data-action", "category-home");
});

$(".back-btn").bind("click", function() {
   alert($(this).data("action")); 
});

But if you click Enter first, then All the value on the Back buttons seems to hold the first value and not get the new one.

I've added a simple jsfiddle to show my issue.

http://jsfiddle.net/uCyJx/1/

1 Answer 1

6

For changing the data attributes use the data function http://api.jquery.com/jQuery.data/:

$(".back-btn").data("action", "search-home");
Sign up to request clarification or add additional context in comments.

1 Comment

Figured it was something simple I was overlooking. Thanks! Will accept as soon as it lets me

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.