0

I am trying to move a div Left a specified amount of pixels I'm using a slider that I got from here:

http://carpe.ambiprospect.com/slider/archive/v1.3/

So from the example my div looks like this:

<div class="horizontal_slider"
        id="your_slider_id"
        style="left: 0px;"
        onmousedown="slide(event, 'your_slider_id',
        'horizontal', 100, 0, 100, 101,
        0, 'your_display_id');" >&nbsp;</div>

And If I adjust left: 0px the slider the move along its line, I've been trying to alter the left from an ajax response that looks like this:

var stateofmindint = $.ajax({ url: "function.php?state=1", async: false }).responseText;

And I try to change its Left style like this:

$("#your_slider_id").css({"left": stateofmindint +"px"});

But for some reason it stays at Left:0px, I've tried to remove the style tag in the div, but to no effect, I also tried referencing the class instead of the ID but nothing seems to be working! I am definitely getting a value everytime through ajax. Any advice would help thank you!

1
  • That looks correct. Check what the stateofmindint variable actually contains. Commented Oct 27, 2010 at 19:40

3 Answers 3

1

Check with an alert/console.log what's the response of your ajax script or try setting "stateofmindint" to a known value in code to test what part has the bug.

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

Comments

1

Theres something weird going on. On that page you link I tried using firebugs console to see the sliders left value with the following

$("#horizontal_slider_2").css("left", "30px");

But jQuery returns null with that selector. The following works:

document.getElementById('horizontal_slider_2').style.left = '30px';

So theres some bug going on with jQuery or that slider code

Comments

0

missing a "+" for your concatenation? looks like your syntax is off

css({"left": stateofmindint +"px"});

should be?

css({"left:" + stateofmindint +"px"});

2 Comments

No, it shouldn't. An object literal is in the form { "name": value }.
That is right, he is using css with an object, so "left" is the key and stateofmindint + "px" is the value. This allows for multiple assignment, though it should be faster when called as css('left', stateofmindint + "px")

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.