ally
ally

Reputation: 1

how can I define a variable in jquery and put a element on it?

how can I define a variable in jquery and put a element on it? what's the rule? i'm new in jquery my html code is

<head>
    <title>Simplify, Simplify</title>
    <script type='text/javascript' src='script.js'></script>
</head>
<body>
    <div> Remember!
        <ul>
            <li>
                <ol>
                    <li>Start with the function keyword</li>
                    <li>Inputs go between ()</li>
                    <li>Actions go between {}</li>
                    <li>jQuery is for chumps!</li>
                </ol>
            </li>
            <li>Inputs are separated by commas.</li>
            <li>Inputs can include other functions!</li>
        </ul>
    </div>   
</body>

and my jquery is:

var target = $("#li:nth-child(4)");
$target.fadeOut('fast');

i want to fade #4 line in list order

Upvotes: 0

Views: 133

Answers (2)

Ji_in_coding
Ji_in_coding

Reputation: 1701

if "#4 line in list order" refers to the the 4th <li> in <ol>

then you can do:

$('ol li:nth-child(4)').fadeOut('fast');

Upvotes: 1

Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85545

You're using variable name as target and using it as $target, should be same:

var target = $("li:nth-child(4)");//if named $target
target.fadeOut('fast');//use $target

target !== $target

And yes, list has no id defined in your html so just use li as the selector instead of #li.

Upvotes: 1

Related Questions