13

Here is html code snippet

<li style="opacity: 1;">
    <a id="LinkDisplay" class="optionsDropDown" style="color:#FF0000;display:none" href="javascript:showThisLink('LinkId');">
</li>

Here is jquery function which is being called at on load

$(function () {
    $.ajax({
        url: url,
        dataType: 'json',
        data: '',
        type: 'POST',
        success: function (data) {
            alert("Test");
            document.getElementById("LinkDisplay").style.diplay="block"; // line 1
            // after this line execution i should see the link as i have
            // changed the link display from none to block but it is still invisible
        });
    });
}

After line 1 execution , I am not sure why my link is not becoming visible?

6 Answers 6

23

you have not changed the display property in your code

 document.getElementById("LinkDisplay").style.display="block"

insert this code into your function after line1

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

1 Comment

It is already block. It was typo mistake. Updated the original post
9

Since you are using jQuery you could just write

$("#elemId").show()

Comments

6

The problem is the spelling of display in the line:

document.getElementById("LinkDisplay").style.display="block";

1 Comment

This is a typo but original prroblem is something else.
2

The parent li is set to opacity: 0, which makes it transparent.

You'll need to update its' opacity to 1 to make it visible.

Replace this:

document.getElementById("LinkDisplay").style.color = "#FF0000";

with this:

$('#LinkDisplay').show().parent('li').css({opacity: 1});

The second line is jQuery (since you're using jQuery already and it's easier to find the parent node) - it's finding the LinkDisplay link and changing the display: none to display: block, then alters the parent li's opacity to make it visible.

Working jsFiddle

Comments

1

Using jQuery:

$('#LinkDisplay').css('display','block');
$('#LinkDisplay').parent().css('opacity','1');

Comments

1

It also looks like you're already using jquery so you can simplify a bit by using the $ selector syntax:

$('#LinkDisplay').css('display', 'block')

You could also use the jQuery show method to shorten the first part like so:

$('#LinkDisplay').show()

The jQuery selector can find elements by ID or classes using the # for id's and . for classes. The jQuery css method allows you to both get and set properties using a variety of methods. And the jQuery parent method quickly allows you to traverse upwards from an element in the DOM to find other tags.

Comments

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.