0

sorry for the poor-explained question before. what i need is to create a cookie which will store some data above some elements on the page, to be speciffic:

  1. a div that has the class "checked"
  2. a checked-state on a checkbox within that div

ive tried jquery-cookie but i dont understand how to utilize it for my script. this is what i need to store (sorry for the silly code):

$(document).ready(function() {
$('.SearchResaultBodyFullUseFulls input[type="checkbox"]').click(function() {
   $(this).parent().parent().parent().parent().parent().parent().toggleClass('checked');
});
});

this is the coockie script that i need to use in my site:

$.cookie('the_cookie', 'the_value');

how do they connect?

you can see the html page here: http://nelband.com/absolute/AgentSearchResaults.html

what i need is that any div named "SearchResault" will save its toggled "checked" class according to the checked / unchecked state its checkbox

thanks!

2
  • Post your HTML please... Commented Nov 7, 2011 at 10:47
  • 2
    Although unrelated to the question chaining calls to parent ie $(this).parent().parent().parent().parent().parent().parent() is very brittle, consider using the .parents method with a suitable selector instead ie $(this).parents('#idOfParent').toggleClass('checked'); Commented Nov 7, 2011 at 10:55

1 Answer 1

1

Assuming I've understood your question, then the following should work for you:

$(document).ready(function() {
    // Check for cookie on page load, and set checkbox value accordingly
    if ($.cookie('MyCookie')) {
        $('.SearchResaultBodyFullUseFulls input[type="checkbox"]').attr("checked","checked");
    }

    // Set cookie on change of value
    // You may consider changing this logic to set the cookie on form submission, 
    // however you've not given enough information about your form for me to show this.
    $('.SearchResaultBodyFullUseFulls input[type="checkbox"]').click(function() {
        $(this).parent().parent().parent().parent().parent().parent().toggleClass('checked');
        $.cookie('MyCookie', $(this).is(":checked"));
    });
});

If you can proved more information about your form (either in a jsFiddle or by posting some HTML) I will be better able to give you a more accurate solution.

Sign up to request clarification or add additional context in comments.

1 Comment

ive added this link - you can see the html page here: nelband.com/absolute/AgentSearchResaults.html what i need is that any div named "SearchResault" will save its toggled "checked" class according to the checked / unchecked state its checkbox

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.