3

How does this slider work?

http://jqueryui.com/demos/slider

source given shows up nothing

<style>
    #demo-frame > div.demo { padding: 10px !important; }
</style>
<script>
    $(function() {
        $( "#slider" ).slider();
    });
</script>
<div class="demo">
    <div id="slider"></div>
</div><!-- End demo -->

I did include jquery before adding this

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>

but it gives me

SCRIPT438: Object doesn't support property or method 'slider'

error.

This is what entire code looks like

<!DOCTYPE html>

<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    </head>
    <body>
        <style>
            #demo-frame > div.demo { padding: 10px !important; }
        </style>

        <div class="demo">
            <div id="slider"></div>
        </div><!-- End demo -->

        <script>
        $(function() {
            $( "#slider" ).slider();
            });
        </script>
    </body>
</html>

What am I missing?

gdoron
  • 147,333
  • 58
  • 291
  • 367
Nitin
  • 175
  • 1
  • 2
  • 9

3 Answers3

2

I did include jquery before adding this

You did include jQuery... but you are using jQuery ui plugin method- .slider() without referencing the ui plugin.
So that method slider is unknown to javascript,

Add the reference after the jQuery library:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

Update:

After too much time spent, I've found your problem, you're missing the JQuery ui css:

<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>

JSFiddle DEMO

gdoron
  • 147,333
  • 58
  • 291
  • 367
  • @Sparky672 (in reply to your now deleted comment) okay... this seems more involved than I thought. It said nowhere in http://jqueryui.com/demos/slider/ that I need images: "The jQuery UI Slider plugin uses the jQuery UI CSS Framework to style its look and feel, including colors and background textures." If I need extra images where do I get those? Or do I have to make my own? – Nitin Feb 06 '12 at 00:22
  • @Nitin, I deleted my last comment because I thought you were trying to construct an image/content slider. It's an overlap in terminology and it's my fault for not looking closer. Disregard. – Sparky Feb 06 '12 at 00:30
1

You should be using jQuery UI for the slider.

<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"/>

Anil
  • 21,730
  • 9
  • 73
  • 100
1

Since it's a jQuery UI Slider, you are missing jQuery UI which needs to be included after jQuery.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript"></script>
Sparky
  • 98,165
  • 25
  • 199
  • 285
  • That URL is valid [try it](http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js) – gdoron Feb 05 '12 at 23:40
  • @gdoron: ok got it. It's technically valid. I'd never leave off the scheme but that's just me. – Sparky Feb 06 '12 at 00:12