-2

i have this js code:

$(function() {
    $('.animate_hoverCard').tooltipster({
        interactive: true,
        content: 'Loading...',
        contentCloning: false,
        contentAsHTML: true,
        animation: 'fade',
        functionBefore: function(origin, continueTooltip) {
            // we'll make this function asynchronous and allow the tooltip to go ahead and show the loading notification while fetching our data.
            continueTooltip();
            origin.tooltipster('content', '<div class="hovercard"> <div> <div class="display-pic"> <div class="cover-photo"> <div class="display-pic-gradient"></div><img src="dp.jpg"> </div><div class="profile-pic"> <div class="pic"> <img src="avatar.jpg" title="Profile Image"> </div><div class="details"> <ul class="details-list"> <li class="details-list-item"> <p> <span class="glyph glyph-home"></span> <span> Also Lives in <a href="#">Chennai</a> <a href="#">TamilNadu</a></span> </p></li><li class="details-list-item"> <p> <span class="glyph glyph-work"></span> <span> Founder at <a href="#">CodeDodle</a></span> </p></li></ul> </div></div></div><div class="display-pic-gradient"></div><div class="title-container"> <a class="title" href="#" title="Visit Page">Tamil Selvan</a> <p class="other-info">2 followers</p></div><div class="info"> <div class="info-inner"> <div class="interactions"> <a href="#" class="btn">Add Friend</a> <a href="#" class="btn">Follow</a> </div></div></div></div></div>');
        }
    });
});

I want to know how to add HTML if statements like this <!-- IF something -->(my code)<!-- ELSE --> &nbsp; <!-- ENDIF -->

Is it possible?

j08691
  • 204,283
  • 31
  • 260
  • 272
  • 5
    HTML doesn't have `if` statements. What are you trying to accomplish? – Mike Cluck Jan 27 '16 at 20:08
  • https://en.wikipedia.org/wiki/Conditional_comment#Conditional_comments_in_JScript – CBroe Jan 27 '16 at 20:09
  • Are you trying to embed the [if statements](http://www.quirksmode.org/css/condcom.html) into the tooltip itself? Or are you trying to not have the tooltip to show for certain browsers? – Chris Jan 27 '16 at 20:26
  • @ chris: Yes.. i trying to insert the if into the tooltip. On this line: origin.tooltipster('content', '
    etc..
    – dr aka Madalin Jan 28 '16 at 18:46

3 Answers3

0

HTML doesn't have if else statements like PHP or other programming languages. Although, you can use if else statements in Javascript to perform certain tasks.

if (hour < 18) {
    greeting = "Good day";
} else {
    greeting = "Good evening";
}

Here is a great resource to learn more about if else statements more indepth. http://www.w3schools.com/js/js_if_else.asp

Ty T.
  • 586
  • 5
  • 18
0

HTML is a markup language. This means it has no if statements. It is not possible in HTML

Check out this question, the user wanted to do the same thing as you.

What you could do is use Javascript for your if/else statements and use document.write() to add content

Check out the following links to pages on MDN:


Here is how you would implement this

Let us say you want to write inside a div with an ID of my_div. You could use the following code:

var div = document.getElementById('my_div')

This will select the div with ID of my_div. It is the equivalent to the CSS selector #my_div

Now to write to that div:

div.innerHTML = 'Some text'

View the Code Snippet below for an example:

var div = document.getElementById('my_div')

if (true) {
 div.innerHTML = 'True!'
}
else {
 div.innerHTML = 'False!'
}
<div id="my_div"></div>
Community
  • 1
  • 1
Kaspar Lee
  • 5,446
  • 4
  • 31
  • 54
-1

No, HTML is a markup language: it has no if statements.

Alessio Cantarella
  • 5,077
  • 3
  • 27
  • 34