0

Lets say I have two elements inside a parent container.

<div class="myclass" id="myid" myvalue="1"></div>
<div class="myclass" id="secid" myvalue="2"></div>

Now I select firstitem, I set the value from spinner and code will be something like selectable plugin but I want to assign values to selected item.

  $('#myspinner').spinner({
        stop: function (event, ui) {
            //change myid myvalue to selected value
        }
    });

How can I change the value of the second element using the same code? My fiddle my example

1
  • How do you get selected value here? Is it coming from the event or ui objects? Commented Jun 20, 2014 at 4:25

2 Answers 2

2
<div class="myclass" id="myid" myvalue="1"></div>
<div class="myclass" id="secid" myvalue="2"></div>

var spinner = $("#spinner").spinner();
    var selectedDiv = '';

    $('.myclass').click(function () {
        selectedDiv = this;
    });

    $('#myspinner').spinner({
        stop: function (event, ui) {
            $(selectedDiv).html(this.value);
        }
    });

The selectedDiv variable will hold the element that has been selected by clicking. When the spinner is stopped, the stop: function is triggered. This will in turn set the html content of the selected div to the value selected using the spinner (this.value)

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

11 Comments

Can you tell us what this does?
When the element with id myid is clicked, its value is changed to the value of element with id myspinner, which is the element on which the jQuery spinner is added to.
thats not wat i mean nikh. your way is reverse as mine.i wan to click the div first and change the value from spinner.i click on next div and change the value from the spinner again on selected div only
Check my edited answer and see if it works for you. You need to focus on the $('#myspinner').spinner('value') part since that will give you the selected value from the spinner. You can assign it to the element you wish to.
I think I know what you're doing now. This spinner of yours is doing some type of spinning and when it stops, "maybe from the user stopping it by clicking on it while it is spinning", triggers the stop event. So, #Nikhil has it right. You'll have to look at the spinner documentation in order to know how to retrieve the value of the selected spinner value. I bet you could set the value like $("#myid").val(this.value); or $("#myid").val(ui.value);
|
0

Your posted code is incorrect. You might want to check it out and re-post it.

If you want a click event to happen when firstitem is clicked then your selector should be $('.firstitem') and not $('#myspinner').

You'll need to make those changes to begin with.

1 Comment

i just wrote it here and didnt test it out

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.