what is wrong with this if else statment

psvj

I am trying to add some text to an html element by its ID randomly changing between a few different cases for different visitors.

For some reason, my text is not being added to the element.

Anyone see whats wrong with my code?

Here is a link to a JSBin thing i set up.

http://jsbin.com/biresocera/1/edit

<script>
    var linkAnchor = $('#link-anchor');
    var randShareLink = Math.floor(Math.random() * 5) + 1;

    $(document).ready(function(){
        if (randShareLink === 1){
            $(linkAnchor).append('case 1');
        } else if (randShareLink === 2){
            $(linkAnchor).append('case 2');
        } else {
            $(linkAnchor).append('case 3');
        }
    });
</script>

<body>
 <div id="link-anchor" style="background-color:red; height:40px; color:white; width:50px;"></div> 
</body>

philz

The code is fine. However, your jsbin is not set up correctly - you need to add the jquery library to make it work.

Also, use linkAnchor.append, as it is already a jquery object.

http://jsbin.com/zokedozibe/1/edit

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What is wrong with these if and else statements?

From Dev

If else Statment not working

From Dev

If Else Statment not working properly

From Dev

If else Statment not working

From Dev

Php If else statment

From Dev

string to if else statment

From Dev

trouble with else statment

From Dev

jQuery ignores if/then/else - what is wrong?

From Dev

What's wrong with this else if statement?

From Dev

What is wrong with my if else statements?

From Dev

What's wrong with this if/else/else if statement?

From Dev

What's wrong with my IF/ELSE? "ELSE: Incorrect syntax near 'ELSE'."

From Dev

Having issues with an else statment for UPDATE into

From Dev

If/Else Statment Breaking for-loop

From Dev

Whats wrong with my select statment?

From Dev

Delete else statement but requires else statment

From Dev

What's wrong with my if-else statement?

From Dev

What's wrong with the conditions in this IF-ELSE?

From Dev

How to change Jbuttons image through if else statment?

From Dev

Using an if/else statment to check that enum arguments exist

From Dev

Adding If / Else If Statment Inside Javascript HTML

From Dev

I'm not able to use scanf() in else statment

From Dev

using when...else statment in port map

From Dev

Using if-else statment in ASP repeater

From Dev

Why is my else statment running the code twice

From Dev

Adding If / Else If Statment Inside Javascript HTML

From Dev

Why does If Else statment not output anything?

From Dev

if..else..in JSP. What's wrong with my code?

From Dev

python 2.7 chained conditions If Else not working. What's wrong?