0

Can some one tell me, Why tag a make my first click without opening the table, but take the address which should go (in first moment table is hidden) first click

And after second click, table is opening and I'm going to it. Without tag <a href="#[email protected]"> it open by 1 click.

#team-**@team.Id** - it's normal, i did 15 tables by cycle, and make for each table id)

My code in view

<div id=team-logo-wrapper>
<ul>
    @foreach (Team team in Model.Item2)
    {
        <li>
            <div class="team-section-box">
                <p class="team-name">@team.Name</p>
                <a href="#[email protected]">
                    <img src="@Url.Content(string.Format("~/Images/NBAlogoImg/{0}", team.Path))" class="logo-images" alt="Логотип @team.Name" title="Логотип @team.Name" onclick="ShowTable(@team.Id)" />
                </a>

            </div>
        </li>
    }
</ul>

in CSS my display and visibility

.table-hidden {
  margin-top: 50px;
  display: none;
  visibility: hidden;
}

the simplest script

var flag = true;
function ShowTable(teamId) {
    var id = "team-" + teamId;
    var getElem = document.getElementById(id);

    if (flag) {
        flag = false;
        getElem.style.display = 'none';
        getElem.style.visibility = 'hidden';
    }

    else {
        flag = true;
        getElem.style.display = 'block';
        getElem.style.visibility = 'visible';
    }
}
4
  • Do you want show table on first click? Commented Jan 8, 2019 at 19:38
  • yes, and after click go to table Commented Jan 9, 2019 at 10:07
  • 1
    I think the problem is flag variable which is default value is true. Commented Jan 9, 2019 at 10:23
  • yor are right, thank you!!!(don't know, why i did't think about flag!) Commented Jan 9, 2019 at 10:50

1 Answer 1

2

When you click on the image, you also activate the link.

If you really need the link, then change it to something like:

<a  href="javascript: void(0)">
  <img src="@Url.Content(string.Format("~/Images/NBAlogoImg/{0}", team.Path))" 
       class="logo-images" alt="Логотип @team.Name" 
       title="Логотип @team.Name" 
       onclick="ShowTable(@team.Id)" />
 </a>
Sign up to request clarification or add additional context in comments.

1 Comment

it helpes, but I have on quastion, if i have 5 tables, open first by 1 click(good), and i want open second table too(dont close first). It openes by second click, why? (if open than close , and next table work right)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.