Prevent default doesn't work when dom reload [duplicate] - html

This question already has answers here:
Event binding on dynamically created elements?
(23 answers)
Closed 2 years ago.
I have the following snippet
$( "#diner_option" ).click(function( event ) {
event.preventDefault();
console.log('ok')
});
$( "#change" ).click(function( event ) {
var add_html = "<div id='diner_div' class='col-md-3 mx-auto planning_recipe_card'><a href='recipes_details.php?recipeid=1'><div class='card card_recipes'><i id='diner_option' class='fas fa-cog recipe_option'></i><img class='img_recipe scard-img-top simg-fluid' src='https://fr.chatelaine.com/wp-content/uploads/0001/01/salade-tiede-courgettes-grillees-10797.jpg' alt='salade tiede de courgettes'><div class='card-body card_body_recipe'><h5 class='card-title'>salade tiede de courgettes</h5></div></div></div></a></div>"
$("#diner_div").replaceWith(add_html)
console.log('changed');
});
.recipe_option{
position: absolute;
padding: 15px;
top: 0;
right: 0;
background: #353b43;
border-bottom-left-radius: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<button id="change">Change</button>
<div id="diner_div" class="col-md-3 mx-auto planning_recipe_card">
<a href="recipes_details.php?recipeid=1">
<div class="card card_recipes">
<i id="diner_option" class="fas fa-cog recipe_option"></i>
<img class="img_recipe scard-img-top simg-fluid" src="https://fr.chatelaine.com/wp-content/uploads/0001/01/salade-tiede-courgettes-grillees-10797.jpg" alt="salade tiede de courgettes">
<div class="card-body card_body_recipe">
<h5 class="card-title">salade tiede de courgettes</h5>
</div>
</div>
</a>
</div>
When I click on cog icon, I get in the console the message ok which means it worked as intended. But when I click on the change button to refresh the dom and click on the cog, the event.preventDefault(); function doesn't work. The cog works like a link then.
I would like to be able to reload the dom and the cog icon still work (which means, shows the ok message)

You have to rebind your click event to the new element that replaces your old cog. Call your jquery bind again.
$( "#diner_option" ).click(function( event ) {
event.preventDefault();
console.log('ok')
});
$( "#change" ).click(function( event ) {
var add_html = "<div id='diner_div' class='col-md-3 mx-auto planning_recipe_card'><a href='recipes_details.php?recipeid=1'><div class='card card_recipes'><i id='diner_option' class='fas fa-cog recipe_option'></i><img class='img_recipe scard-img-top simg-fluid' src='https://fr.chatelaine.com/wp-content/uploads/0001/01/salade-tiede-courgettes-grillees-10797.jpg' alt='salade tiede de courgettes'><div class='card-body card_body_recipe'><h5 class='card-title'>salade tiede de courgettes</h5></div></div></div></a></div>"
$("#diner_div").replaceWith(add_html);
$( "#diner_option" ).click(function( event ) {
event.preventDefault();
console.log('ok')
});
console.log('changed');
});
.recipe_option{
position: absolute;
padding: 15px;
top: 0;
right: 0;
background: #353b43;
border-bottom-left-radius: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<button id="change">Change</button>
<div id="diner_div" class="col-md-3 mx-auto planning_recipe_card">
<a href="recipes_details.php?recipeid=1">
<div class="card card_recipes">
<i id="diner_option" class="fas fa-cog recipe_option"></i>
<img class="img_recipe scard-img-top simg-fluid" src="https://fr.chatelaine.com/wp-content/uploads/0001/01/salade-tiede-courgettes-grillees-10797.jpg" alt="salade tiede de courgettes">
<div class="card-body card_body_recipe">
<h5 class="card-title">salade tiede de courgettes</h5>
</div>
</div>
</a>
</div>

Related

Switching fas fa icon through javascript - Dark / Light mode

Don't know where I am going wrong, but the icon just doesn't change.
$( ".inner-switch" ).on("click", function() {
if( $( "body" ).hasClass( "dark" )) {
$( "nav" ).removeClass( "dark-force" );
$( "body" ).removeClass( "dark" );
$(this).find("i").toggleClass("fas fa-moon");
} else {
$( "body" ).addClass( "dark" );
$( "nav" ).addClass( "dark-force" );
$(this).find("i").toggleClass("fas fa-sun");
}
});
.dark {
background-color: #222;
}
.dark-force * {
background-color: #222;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css" />
<nav class="navbar">
<div class="hero-body">
<div class="container">
<div class="navbar-brand">
<a href="/">
<img src="{% static 'portfolio/Logo.png' %}" width=60>
</a>
<div class="navbar-end">
<div class="navbar-item">
<div class="buttons">
<a class="button is-primary is-rounded is-outlined">
<strong>Blog</strong>
</a>
</div>
</div>
<div class="navbar-item">
<div class="buttons">
<a class="button is-primary is-rounded">
<strong>Say Hello!</strong>
</a>
</div>
</div>
<div class="navbar-item">
<div class="buttons">
<a class="button is-primary is-rounded inner-switch">
<i class="fas fa-moon"></i>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</nav>
It does switch to dark mode, but the icon refuses to change from the moon(fas fa-moon). I'm new to javascript but fairly familiar with HTML and CSS. Any help is appreciated. Have a great and safe day! Thanks for reading!
You are nearly there and your code looks good but you need to use addClass and removeClass to switch fas fa icon from sun to moon and vice versa.
$(this).find("i").removeClass("fa-sun").addClass('fa-moon');
When you use toggleClass the existing is still there and new icon is not working as it suppose to.
Live Working Demo:
$(".inner-switch").on("click", function() {
if ($("body").hasClass("dark")) {
$("nav").removeClass("dark-force");
$("body").removeClass("dark");
$(this).find("i").removeClass("fa-sun").addClass('fa-moon');
} else {
$("body").addClass("dark");
$("nav").addClass("dark-force");
$(this).find("i").removeClass("fa-moon").addClass('fa-sun');
}
});
.dark {
background-color: #222;
}
.dark-force * {
background-color: #222;
}
.fa-sun {
color: white;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://kit.fontawesome.com/a076d05399.js"></script>
<div class="navbar-item">
<div class="buttons">
<a class="button is-primary is-rounded inner-switch is-outlined">
<i class="fas fa-moon"></i>
</a>
</div>
</div>
The problem is that you only toggle the sun and moon class every second time.
You need to toggle them both every time!
$(this).find("i").toggleClass("fa-moon").toggleClass("fa-sun");
FYI you don't need to toggle the fas class because you always need it. Also, you don't need to duplicate the code by putting this inside the if/else - as you need to toggle them both every time you click, you can just include this line once directly in the function.
Working example:
$(".inner-switch").on("click", function() {
// toggle moon and sun every time
$(this).find("i").toggleClass("fa-moon").toggleClass("fa-sun");
if ($("body").hasClass("dark")) {
$("nav").removeClass("dark-force");
$("body").removeClass("dark");
} else {
$("body").addClass("dark");
$("nav").addClass("dark-force");
}
});
.dark {
background-color: #222;
}
.dark-force * {
background-color: #222;
}
.button {
font-size: 3em;
color: #f00
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css" />
<div class="navbar-item">
<div class="buttons">
<a class="button is-primary is-rounded inner-switch is-outlined">
<i class="fas fa-moon"></i>
</a>
</div>
</div>
You also need to toggle the font color when you toggle the background color.
$("#lightswitch i").click(function() {
var isDark = $("body").is(".dark");
$("body").toggleClass("dark", !isDark);
$(this).toggleClass("fa-moon", isDark).toggleClass("fa-sun", !isDark);
});
body.dark {
background-color: #222;
color: white;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css" />
<body>
<div class="navbar-item">
<div class="buttons">
<a id="lightswitch" class="button is-primary is-rounded inner-switch is-outlined">
<i class="fas fa-moon"></i>
</a>
</div>
</div>
</body>

How to show tooltip only for a particular hovering div which are dynamically generated

I have the following div
<div class="col-sm" title="Device Name" id="titleDevice" data-toggle="tooltip" data-placement="bottom"><i class="fab fa-500px"></i> Name</div>
I am trying to show tooltip as below by pointing to the id of this element. This is working fine.
showTooltip("#titleDevice");
function showTooltip(idOfElement) {
$(idOfElement).hover(function() {
$(idOfElement).tooltip('show');
});
}
My issue is, in the page, sometimes there will be many such div which are dynamically generated. For that case, this selecting by id will not work and thus I tried selecting by class.
Example of such scenario with some number of div as below
<form method="post" id="qaForm">
<div class="card" style="background-color:white; color: white; position: relative; border-color: black; !important ">
<div class="card-body">
<div class="row">
<div class="col-sm" title="Device Name" class="titleDevice" data-toggle="tooltip" data-placement="bottom"><i class="fab fa-500px"></i> Name</div>
<div class="col-sm" title="second" class="second" data-toggle="tooltip" data-placement="bottom"><i class="fab fa-500px"></i> Second</div>
<div class="col-sm" title="third" class="third" data-toggle="tooltip" data-placement="bottom"><i class="fab fa-500px"></i>third</div>
</div>
</div>
</form>
showTooltip(".titleDevice");
function showTooltip(classOfElement) {
$(classOfElement).hover(function() {
$(classOfElement).tooltip('show');
});
}
Then used the same JQuery function. But when I hover over to one div, all the other div also showing the tooltip at the same time. Does anyone know how to solve this problem?
To show the tooltip for only that particular element, use this keyword
showTooltip(".titleDevice");
function showTooltip(idOfElement) {
$(idOfElement).hover(function() {
$(this).tooltip('show'); // Use 'this' here
});
}
If you want tooltip for dynamically generated div then use only
$(document).tooltip();
This will work for all div. You need not include the hover method.
You can preview below code:
$(document).tooltip();
//for dynamically add
$(document).on('click', '#add', function(){
$('#div').html('<div class="col-sm" title="Mobile Name" data-toggle="tooltip" data-placement="bottom"><i class="fab fa-500px"></i> Name</div>');
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<div class="col-sm" title="Device Name" id="titleDevice" data-toggle="tooltip" data-placement="bottom"><i class="fab fa-500px"></i> Name</div>
<hr />
<button id="add">Add New</button>
<hr />
<div id="div"></div>

Change size of one Bootstrap 3 tooltip only

I am using Bootstrap 3 tooltip but on one page i want to increase the size of them.
I don't want to affect the rest of the site.
I have tried the following code but it doesn't work so i was wondering if i have the syntax wrong or something.
$(document).ready(function() {
$('[data-toggle="tooltip"]').tooltip();
});
.dashboard+.tooltip>.tooltip-inner {
max-width: 350px;
width: 350px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="row">
<div class="col-xs-12 col-md-7">
<p>This week:</p>
</div>
<div class="col-xs-12 col-md-4">
<p id="extTotalThisWk" class="dashboard" data-html="true" data-toggle="tooltip" data-placement="bottom" style="cursor: pointer" data-original-title="
<span class='text-left'>
<p style='padding-top: 5px'>This total number is made up from:</p>
<ul style='padding-bottom: 5px'>
<li>Added this week - Deleted this week</li>
</ul>
</span>">123</p>
</div>
<div class="hidden-xs col-md-1"></div>
</div>
I have also tried it without the +.tooltip in the CSS but it still doesn't apply it.
Also i have tried the following but still didn't work
<span class='text-left' style='max-width: 350px; width: 350px;'>
Obviously if i just use .tooltip-inner it works but this affects the whole site which i don't want to do.
If it is about selecting only that tooltip inside #extTotalThisWk, then you can use the id as a selector .
#extTotalThisWk + .tooltip > .tooltip-inner
$(document).ready(function() {
$('[data-toggle="tooltip"]').tooltip();
});
#extTotalThisWk + .tooltip > .tooltip-inner {
max-width: 350px;
width: 350px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<p id="extTotalThisWk" class="dashboard" data-html="true" data-toggle="tooltip" data-placement="bottom" style="cursor: pointer" data-original-title="
<span class='text-left' >
<p>This total is:</p>
<div>Added this week - Deleted this week</div>
</span>">
123</p>
<p id="extTotalThisWkBis" class="dashboard" data-html="true" data-toggle="tooltip" data-placement="bottom" style="cursor: pointer" data-original-title="
<span class='text-left' >
<p>This total is:</p>
<div>Added this week - Deleted this week</div>
</span>">
another one , another id</p>
It is about
https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity
Specificity is the means by which browsers decide which CSS property values are the most relevant to an element and, therefore, will be applied. Specificity is based on the matching rules which are composed of different sorts of CSS selectors.
You can wrap your code inside a div and can use > selector from parent class.Make sure that span elements are inline, so set them to block and give the style to it. Below is the working snippet
$(document).ready(function() {
$('[data-toggle="tooltip"]').tooltip();
});
.main-holder>.tooltip>.tooltip-inner {
max-width: 500px;
text-align: center
}
span.text-left {
display: block;
width: 400px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="main-holder">
<p id="extTotalThisWk" class="dashboard" data-html="true" data-toggle="tooltip" data-placement="bottom" style="cursor: pointer" data-original-title="
<span class='text-left'>
<p>This total is:</p>
<div>Added this week - Deleted this week</div>
</span>">
123</p>
</div>

background-image responsive with width 60% [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
How can I set div with background-image and with 60% to be responsive?
I have navbar (div) in top of site, with margin-left and margin-right 20%, responsive works here.
Under this, is another div, too with margin-left and margin-right 20%, with background-image and here responsive doesn't works.
Second question: if i have 3 divs same line with images (1 img in 1 div), if they cant be located in 1 line because resolution of user, how to "explode" them to 2 or 3 lines?
if needed, demo: http://tlumacz-litewskiego.eu/
It seems like you are just learning so I thought I would take a minute and give a little guidance. First, you should understand that Bootstrap is a framework that allows you to achieve much of what you are trying to do. As you can see, the elements are now lined up and justified yet I used Bootstrap to achieve this, not additional css. Furthermore, as the screen collapses down to mobile, you can control when things stack as you were mentioning you wanted to do. Also, you will see that by using Bootstrap, a lot less styles are needed to achieve the desired result.
Example: http://jsbin.com/beruqorinu/edit?output
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<header>
<div class="container">
<div class="row">
<div id="header" class="col-sm-12">
<h1>Tłumacz-litewskiego</h1>
</div>
</div>
<div id="menu_container" class="row">
<div class="col-sm-12">
<nav>
<i class="fa fa-home"></i> Strona główna
</nav>
</div>
</div>
<div id="main_image" class="row">
<div class="col-sm-8 bookbox">
<h2>Tłumacz języka litewskiego</h2>
<h4>mgr Živilė Wygońska</h4>
<img class="img-responsive" src="http://tlumacz-litewskiego.eu/img/book.png">
</div>
<div class="col-sm-4 contact">
<i class="fa fa-globe"></i> Polska, Podlaskie, Suwałki<br />
<i class="fa fa-phone"></i> <b>Tel:</b> +48 515 231 589<br />
<i class="fa fa-envelope-o"></i> <b>Email:</b> zivile.wygonska#gmail.com
</div>
</div>
</div>
</header>
<section id="info">
<div class="container">
<div class="row">
<div class="col-sm-4">
<h3><i class="fa fa-book"></i> O mnie</h3>
<img src="http://tlumacz-litewskiego.eu/img/slide1.jpg" class="img-responsive">
<p>Litewski to mój ojczysty język, większość życia mieszkałam na Litwie, gdzie studiowałam filologię litewską na Uniwersytecie Wileńskim.</p>
<div class="collapse" id="cl1">
<p>Po przeprowadzce do Polski na Uniwersytecie Warszawskim w Instytucie Języka I Kultury Polskiej Dla Cudzoziemców uzyskałam świadectwo znajomości języka polskiego. Ukończyłam pedagogikę na Uniwersytecie w Białymstoku.</p>
<p>Posiadam dziesięcioletnie doświadczenie jako tłumacz języka litewskiego. Przez te 10 lat, pracując z różnymi klientami, przetłumaczyłam setki stron o przeróżnej tematyce, m.in. turystyka, sprawozdania, statuty, przetargi, strony www, artykuły, etykiety, instrukcje obsługi, katalogi, foldery reklamowe, dokumentacje sądowe i wiele wiele innych.</p>
</div>
<a role="button" data-toggle="collapse" href="#cl1" aria-expanded="false" aria-controls="collapseExample1" id="element1" onclick="changeText(1)">Więcej...</a>
</div>
<div class="col-sm-4">
<h3><i class="fa fa-newspaper-o"></i> Oferta</h3>
<img src="http://tlumacz-litewskiego.eu/img/slide2.jpg" class="img-responsive">
<p>Tłumaczenia ustne, pisemne, nauka języka litewskiego i korepetycje.</p>
<div class="collapse" id="cl2">
<p><b>Tłumaczenia pisemne:</b> Tłumaczę teksty na język litewski oraz z języka litewskiego. Przetłumaczyłam m.in. kilkanaście katalogów, opowiadania, różne dokumenty, umowy, projekty i dokumenty związanie z realizacją projektów unijnych.</p>
<p><b>Tłumaczenia ustne:</b> tłumaczenie konferencyjne, symultaniczne (możliwość wynajmu sprzętu dla tłumaczeń symultanicznych), konsekutywne, towarzyszące, szeptane.</p>
<p><b>Nauka języka litewskiego i korepetycje:</b> prowadzę kursy nauki języka litewskiego na wszystkich poziomach dla klientów indywidualnych oraz instytucji.</p>
<p>Każde zlecenie jest traktowane indywidualnie, swoją pracę wykonuję rzetelnie i solidnie. Na życzenie klienta mogę przedstawić referencje zadowolonych klientów. </p>
<p>Gwarantowane bezpieczeństwo przekazywanych dokumentów oraz informacji. Każdy dokument jest traktowany jako poufny. Wykonane tłumaczenie jest archiwizowane przez okres 12 miesięcy. </p>
<p><b>Cena</b> tłumaczenia zależy od stopnia trudności tekstu, rodzaju tłumaczenia oraz terminu realizacji. Istnieje możliwość negocjacji cen przy większych zleceniach. </p>
1 strona obliczeniowa to 1600 znaków ze spacjami 12-punktową czcionką Times New Roman.</p>
</div>
<a role="button" data-toggle="collapse" href="#cl2" aria-expanded="false" aria-controls="collapseExample2" id="element2" onclick="changeText(2)">Więcej...</a>
</div>
<div class="col-sm-4">
<h3><i class="fa fa-users"></i> Klienci</h3>
<img src="http://tlumacz-litewskiego.eu/img/slide3.jpg" class="img-responsive">
<p>Urząd Miasta Suwałki<br />
Regionalny Ośrodek Kultury i Sztuki w Suwałkach<br />
Suwalski Ośrodek Kultury...</p>
<div class="collapse" id="cl3">
<p>Wigierski Park Narodowy<br />
Muzeum Wigier (Stary Folwark)<br />
Starostwo Powiatowe w Suwałkach<br />
Urząd Miasta w Giżycku<br />
Centrum Informacji Turystycznej w Giżycku, Wydawnictwo Mazurskie S.C.<br />
Podlaska Regionalna Organizacja Turystyczna<br />
oraz inni.</p>
</div>
<a role="button" data-toggle="collapse" href="#cl3" aria-expanded="false" aria-controls="collapseExample3" id="element3" onclick="changeText(3)">Więcej...</a>
</div>
</div>
</div>
</section>
<footer>
<div class="container">
<div id="copyright" class="row">
<div class="col-sm-12">
© 2015 tlumacz-litewskiego.eu
</div>
</div>
</div>
</footer>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-65084817-1', 'auto');
ga('send', 'pageview');
</script>
<script type="text/javascript">
function changeText(idElement) {
var element = document.getElementById('element' + idElement);
if (idElement === 1 || idElement === 2 || idElement === 3) {
if (element.innerHTML === 'Więcej...') element.innerHTML = 'Mniej...';
else {
element.innerHTML = 'Więcej...';
}
}
}
</script>
</body>
</html>
CSS:
header h1 {
margin-bottom: 20px;
font-size: 40px;
}
nav {
padding-top: 6px;
padding-bottom: 6px;
margin-bottom: 20px;
font-size: 24px;
border-top: 2px solid #C7C7C7;
border-bottom: 2px solid #C7C7C7;
}
#main_image {
background: url(http://tlumacz-litewskiego.eu/img/bg.jpg) no-repeat center center;
background-size: cover;
}
.bookbox,
.contact {
padding: 20px;
}
.bookbox img {
max-width: 128px;
}
.contact {
font-size: 16px;
color: white;
}
.contact i {
margin-right: 2px;
}
#info {
text-align: center;
}
#copyright {
margin-top: 20px;
text-align: right;
}
I have done this for you in the hopes that it will serve as an example so can learn how to properly lay things out. Several recommendations:
Try to avoid using inline css (directly in your html)
Avoid using percentages if possible. Bootstrap is a fixed pixel framework.
Visit http://getbootstrap.com and go through the docs, most importantly the Getting Started page (and see the examples).
Hope this helps!

how to insert user-glyphicon in img tag

The problem is :- In below code I want to make it, if there is no photo uploaded then there will be a photo size bootstrap's glyphicon-user should be placed and when photo uploaded this will overwrite by the uploaded image.
//please add necessary files of bootstrap
<div class="row">
<div class="row">
<div class="col-md-4">
<h4 class="heading">Upload Patient's Photo :-</h4>
</div>
<div class="col-md-4">
<input type="file" class="form-control" name="patientpic" id="patientpic" onchange="readURL(this)"/>
</div>
</div>
//this is the script code for preview image when uploaded.
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#patientimg').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
</script>
</div>
//this is image code here changes takes place to add bootstrap's glyphicon-user
<div class="col-md-2 col-sm-12">
<div class="thumbnail">
<img src="" alt="Select Patient Image" class="img-responsive" id="patientimg" name="patientimg" style="height:140px;width:140px;font-size:30px;text-align:center;color:gray;"/>
</div>
</div>
I tried this but the glyphicon-user in span tag reside below patient image.
just suggestion here, why not convert the bootstrap's glyphicon-user to png then add it on since when the user upload the image it will be appended according to your code.
check a sample here http://jsfiddle.net/ws3bb7sr/1/
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#patientimg').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<div class="row">
<div class="row">
<div class="col-md-4">
<h4 class="heading">Upload Patient's Photo :-</h4>
</div>
<div class="col-md-4">
<input type="file" class="form-control" name="patientpic" id="patientpic" onchange="readURL(this)"/>
</div>
</div>
<div class="col-md-2 col-sm-12">
<div class="thumbnail">
<img src="http://s5.postimg.org/4xpbh5oo3/user_000000_128.png" alt="" class="img-responsive" id="patientimg" name="patientimg" style="height:140px;width:140px;font-size:30px;text-align:center;color:gray;"/>
</div>
</div>
Not the best idea, but you can use this code:
<html>
<head>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="//code.jquery.com/jquery-2.1.3.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
#img1 {
width: 100px;
height: 100px;
margin-left: 25px;
}
#img1::before {
position: absolute;
font-size: 100px;
}
</style>
<script>
$(function() {
setTimeout(function() {
$('#img1').attr('src', 'http://dummyimage.com/100x100/0ac72a/0011ff');
}, 2500);
});
</script>
</head>
<body>
<img src="" id="img1" class="glyphicon glyphicon-asterisk">
</body>
</html>
You might have some problems with transparent png files, so in better check it. If you have some problem with it you can remove the glyphicon classes when you update the src of your image.