changing the content of div by click and change back another click - html

I want to change the contents of a div using a button click and in another click I want to bring back the old contenns to div I am using a image for button...
My div code is below
<div class="pic-container" style="position:absolute; left: 3px; top: 102px;">
<div class="pic-row" >
<img src="images/A.Png" />
<img src="images/B.Png" />
<img src="images/C.Png" />
<img src="images/D.Png" />
<img src="images/E.Png" />
<img src="images/F.Png" />
<img src="images/G.Png" />
<img src="images/H.Png" />
<img src="images/I.Png" />
<img src="images/J.Png" />
<img src="images/K.Png" />
<img src="images/L.Png" />
<img src="images/M.Png" />
<img src="images/N.Png" />
<img src="images/O.Png" />
<img src="images/P.Png" />
<img src="images/Q.Png" />
<img src="images/R.Png" />
<img src="images/S.Png" />
<img src="images/T.Png" />
<img src="images/U.Png" />
<img src="images/V.Png" />
<img src="images/W.Png" />
<img src="images/X.Png" />
<img src="images/Y.Png" />
<img src="images/Z.Png" />
</div>
</div>
<img style="position:absolute; left: 272.5px; top: 647px; width: 171px; height: 122.5px;" src="images/Btn_Lower.png" id="image1" />
Please help me to solve this issue

I don't want to confuse you by solving your problem, instead I would like to give you a short and simple example.
You can't achieve it by only using HTML you need javascript. So here is a way.
1) When you say content, it is referred as innerHTML in javascript.
2) I think you know about onclick, it is called click event. Similar to that you have a lots of different events in javascript for keypress, doubleclick, etc.,
3) Hope you know ID, called as unique selector. Other selector like class and you can HTML5 data-attributes.
4) To select an element, in JS you can use different methods like,
document.getElementById // select element based on Unique ID
document.getElementsByClassName // select element based on class
document.getElementsByTagName // select element based on Tag name
If you're insterested to learn more about javascript refers Mozilla Developers Network
Here is the shot example I would like to present to you.
HTML:
<div id="divd">First</div>
<button onclick='changeMe()'>Click It</button>
JS:
function changeMe() {
var div = document.getElementById('divd').innerHTML;
if (div === 'First') {
document.getElementById('divd').innerHTML = "Second";
} else {
document.getElementById('divd').innerHTML = "First";
}
}
Demo

Related

What happens with vue when i pass <object> tag in template?

I stuck with some strange behaviour in vue.
The result
The code
<template>
<div class="container">
<main class="messages">
<message v-for="message in messages" v-bind="message" :key="message.id" />
</main>
<div class="send-message">
<g-input v-model="message" :maxLength="80" #submit="sendMessage">
<object type="image/svg+xml" data="assets/send-icon.svg" width="200" height="200">
<img src="assets/send-icon.png" width="200" height="200" alt="image format png" />
</object>
</g-input>
</div>
</div>
</template>
g-input code
<template>
<div class="root">
<canvas ref="canvas" class="hide"></canvas>
<textarea
ref="input"
class="input"
type="text"
:rows="lineCount"
:maxlength="maxLength"
:value="value"
#input="handleInput"
#keydown.prevent.enter="handleEnter"
/>
<div ref="confirmButton" class="confirm-button">
<slot></slot>
</div>
<span class="char-counter">{{ `${charCount}/${maxLength}` }}</span>
</div>
</template>
I absolutely do not understand why this happens, can you please explain?
So I found how to avoid this
Just need to replace data attribute in object like this
<object type="image/svg+xml" :data="sendIcon" width="200" height="200">
<img src="#/assets/send-icon.png" width="200" height="200" alt="image format png" />
</object>
Then in script tag we need to export icon
const sendIcon = require('#/assets/send-icon.svg')
export default {
data: () => ({
sendIcon: sendIcon,
}),
}
But I still do not understand wht this is happens cause single <img> tag works just fine
<img src="#/assets/send-icon.svg" width="200" height="200" alt="image format png" />
And only <object> tag produce this behaviour and only with local url, some http url works fine
<object
type="image/svg+xml"
data="https://upload.wikimedia.org/wikipedia/commons/1/12/Black_Paw.svg"
width="200"
height="200">
<img
src="https://upload.wikimedia.org/wikipedia/commons/1/12/Black_Paw.svg"
width="200"
height="200"
alt="image format png"
/>
</object>

How to access child element of sibling of its parent in html by css

Can anyone tell how I can access a child element of an element which sibling of an element of parent of current attribute?
<div class="views-field views-field-field-mobile-service-new-image">
<div class="field-content">
<img typeof="foaf:Image" src="image1.png" width="55" height="55" alt="" />
</div>
</div>
<div class="views-field views-field-view-node">
<span class="field-content">
<a href="#" class="colorbox-node" data-inner-width="650" data-inner-height="450">
<img typeof="foaf:Image" src="image2.png" width="55" height="55" alt="" />
</a>
</span>
</div>
how I can access image in other div on hover of class field-content which is child of first div
Is it like, when you hover on image of one div at that time the second div image should be replaced by the first div's img?
If i understand you well, you can't do this with the CSS, but you can do it with JS, smth like that:
$('.views-field-view-node img').hover(function() {
var $yourImage = $(this).closest('.views-field-view-node')
.parent().find('.views-field-field-mobile-service-new-image img').addClass('hover');
}, function() {
var $yourImage = $(this).closest('.views-field-view-node')
.parent().find('.views-field-field-mobile-service-new-image img').removeClass('hover');
});
It's only example, you can improve my code and make it better, if you want.

repeating an embedded data URI image

Let's say I have an embedded image in an HTML file using a data URI (e.g. <img src="data:image/png;base64,...." />.
Is there any way to show that image several times, with subsequent images referring to the initial one, without having to repeat the data URI? for example (though a bad one):
<html><head>...</head>
<body>
<p>Here's my car:</p>
<img id="img1" src="data:image/png;base64,..." />
<p>Some details about my car</p>
<p>Did I mention I just bought a car?</p>
<p>And here it is again:</p>
<img something_to_show_another_image_again="#img1" />
...
</body>
</html>
Seems a bit of an odd situation. Usually you would achieve this by having the image data in a separate file and then each image loading that source.
Ideally you would move the data to a separate file but if that's not an option maybe you could use the data-uri as a background image to each element? Failing that, you could use JavaScript to set the source of each image.
The following snippet includes examples of both.
var images = document.querySelectorAll("#JS img");
var src = images[0].src;
for (var i = 0; i < images.length; ++i) {
images[i].src=src;
}
#CSS img {
width: 20px;
height: 20px;
background: url(data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7) center center no-repeat;
}
<div id="CSS">
<p>The image src is empty but the background is defined in the stylesheet:</p>
<img src="" />
<img src="" />
<img src="" />
<img src="" />
<img src="" />
</div>
<hr />
<div id="JS">
<p>Here we use JavaScript to set the source of all these images to match that of the first:</p>
<img src="data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7" />
<img src="" />
<img src="" />
<img src="" />
<img src="" />
</div>
Update...
Further to your updated question I've explored a JS solution that seems to meet your requirements (assuming JS is allowed):
(function linkAliasedImages(){
var aliasedImages = document.querySelectorAll("img[src*='#']");
for (var i = 0; i < aliasedImages.length; ++i) {
var aliasID = aliasedImages[i].src;
aliasID = (aliasID.substring(aliasID.indexOf("#")+1));
var source = document.getElementById(aliasID).src;
aliasedImages[i].src=source;
}
})();
<p>Here's my star:</p>
<img id="img1" src="data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7" />
<p>Some details about my star</p>
<p>Did I mention I just bought a star?</p>
<p>And here it is again:</p>
<img src="#img1" />
<p>And again:</p>
<img src="#img1" />
<img style="background: url(URI) repeat-x;width:100px;" />
Width have to be more than you're image width.

Structure of web page. Huge gap. HTML or CSS issue?

Hi there,
I am trying to build a web page and i have the following problem. I tried to upload a photo but I cannot because I don't have enough votes. I have a contacts page and my problem is that there is a huge gap between the contacts (little photos with people) and the grey layer in the bottom (please vote for me so that I can upload a photo to show you what I mean). I am really confused and I don't know where the problem might be. Here I give some information:
I have created two lists (divs) with photos and contacts (in this picture you can see 2 photos of the leftlist (as i called it) div and one photo of the rightlist div.
The CSS for these two are the following:
#leftlist {
width:430px;
position: relative;
left: 0px;
top: 0px;
bottom: 720px;}
#rightlist {
width:430px;
position: relative;
left: 450px;
bottom: 720px;
top: -670px;}
These two divs I placed them inside the white box as you can see from the photo which I named container. The CSS for container is:
.container {
width:950px;
margin-top: 0;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;}
Here I add the whole code of the container including whats inside:
<div class="container">
<div class="box">
<div class="border-top">
<div class="border-right">
<div class="border-bot">
<div class="border-left">
<div class="left-top-corner">
<div class="right-top-corner">
<div class="right-bot-corner">
<div class="left-bot-corner">
<div class="inner">
<h2> </h2>
<h2 align="center">Sales and Customer Service Team</h2>
<h2 align="center"><br />
<br />
</h2>
<div id="leftlist">
<ul class="list2">
<li>
<img alt="" src="images/blabla.jpg" />
<h4><strong>blabla </strong>
President<br />
<br />
<span class="style100">Email: blabla#sblabla.it</span><br />
<span class="style100">Tel: +39 02 00000001</span><br />
</h4></li>
<li></li>
<br />
<li>
<img alt="" src="images/blabla.jpg" />
<h4><strong>blabla </strong>
General Sales Manager<br />
<br />
<span class="style100">Email: blabla#blabla.it</span><br />
<span class="style100">Tel: +39 02 00000023</span><br />
</h4>
</li>
<li></li>
<br />
<li>
<img alt="" src="images/blabla.jpg" />
<h4><strong>blabla </strong>
Sales Manager<br />
<br />
<span class="style100">Email: blabla#sblabla.it</span><br />
Tel: +39 02 00000021<br />
</h4></li>
<li></li>
<br />
<li>
<img alt="" src="images/lara.jpg" />
<h4><strong>Lara blabla</strong>
Sales and Logistics<br />
<br />
<span class="style100">Email: lara.blabla#blabla.it</span><br />
Tel: +39 02 00000022<br />
</h4></li>
<li></li>
<br />
</ul>
</div>
<div id="rightlist">
<ul class="list2">
<li>
<img alt="" src="images/blabla.jpg" />
<h4><strong>blabla</strong>
Laboratory Manager and Quality Control<br />
<br />
<span class="style100">Email: blabla#blabla</span><br />
Tel: +39 02 00000020<br />
</h4></li>
<li></li>
<br />
<li>
<img alt="" src="images/blabla.jpg" />
<h4><strong>blabla</strong>Technical Department<br />
<br />
<span class="style100">Email: blabla#blabla.it</span><br />
Tel: +39 02 00000012<br />
</h4></li>
<li></li>
<br />
<li>
<img alt="" src="images/blabla.jpg" />
<h4><strong>blabla</strong>Safety Manager<br />
<br />
<span class="style100">Email: blabla#blabla.it</span><br />
Tel: +39 02 00000011<br />
</h4></li>
<li></li>
</ul>
</div>
</div>
<div align="center"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- box end -->
</div>
Tip: there are more photos and contact details that are not visible in the photo I upload as i wanted to show you the gap between the container div and the next div (grey layer).
I am really sorry in advance if I am asking something stupid but I've been working on this for 8 hours now and I can't seem to find a solution. Maybe the solution is really stupid but my brain feels like its frying right now :p
Right, there are a couple of issues with the code you have here, most notably the number of divs you are using (I assume that's just for the rounded corners?). However I believe your issue is caused by the positioning of the #leftlist and #rightlist. I can't see a reason for these to be position:relative (also when used you should only set the top value or the bottom value, not both (e.g. 'top:0px' OR 'bottom:0px').)
What is happening is you are moving the #rightlist from it's default position under the #leftlist. Because you are using position:relative and not position:absolute the original position is retained. The extra whitespace you are seeing is where the #rightlist should, by default, appear.
I would not use position in this instance. A better alternative is to use 'float:left' on both lists. If you do this your css will end up being the same for each list - try this:
#leftlist
#rightlist {
width:430px;
float:left;
}
This may collapse the #container div which can be fixed in a number of ways, the simplest being adding 'overflow:hidden;height:100%' to #container. A quick google search should provide many more options if required.
Another alternative would be to use 'display:inline-block' instead of 'float:left' although this can cause issues in older browsers - it really depends on what browsers you need to support.
Hope this helps put you on the right track. Please leave a comment if I'm not being clear and I'll edit my response!
You could try the following in order to attempt to identify where the problem lies:
Install the Web Developer add-on in Firefox, load up your page then use the 'Outline Block Level Elements' option to get a visual display of all the elements that make up your page.

Why does my div disappear when i use position:relative in IE6?

I have no margins applied to this particular div, no floats and more annoyingly it works on a different page. Below is the code for the css rule:
#prizedraw-fliemore{
position: relative;
top: 164px;
left: -720px;
z-index: 3000;
}
The div shows up when i use position:absolute but that is useless to me. I have tried display, visibility and nothing i try works. Can someone help me out please? Thanks
The page code is:
<div id="column-left-content">
<p class="height"><strong>Learn more about CAREFREEĀ® pantyliners and discover how they can help you feeling clean, fresh and protected all day long.</strong></p>
</div>
<div id="column-right-content">
<p><strong>Free to be me</strong> has been put together for you by the thoughtful makers of CAREFREEĀ®, who design feminine hygiene products to give you all the protection you need.<br /><br />
Now that you've reached puberty, there are things you need to know that you might not know already. CAREFREEĀ® has the answers to some of the questions you might just be asking...
</p>
</div>
<div id="car-boxes">
<div class="car-nav">
<div class="container">
<a class='example5' href="lb/why.html" style="border:none;" rel="group"><img src="images/carefree/pantyliners.png" class="bw" style="border:none;" /></a>
<img src="images/carefree/pantyliners-y.png" class="colour" alt="" />
</div>
</div>
<div class="car-nav">
<div class="container">
<a class='example5' href="lb/discharge.html" style="border:none;" rel="group"><img src="images/carefree/discharge.png" class="bw" style="border:none;" /></a>
<img src="images/carefree/discharge-y.png" class="colour" alt="" />
</div>
</div>
<br />
<div class="car-nav">
<div class="container">
<a class='example5' href="lb/difference.html" style="border:none;" rel="group"><img src="images/carefree/difference.png" class="bw" style="border:none;" /></a>
<img src="images/carefree/difference-y.png" class="colour" alt="" />
</div>
</div>
<div class="car-nav">
<div class="container">
<a class='example1' href="lb/right.html" style="border:none;" rel="group"><img src="images/carefree/right.png" class="bw" style="border:none;" /></a>
<img src="images/carefree/right-y.png" class="colour" alt="" />
</div>
</div>
</div>
<div id="prizedraw-car">
<img src="images/prizedraw.png" alt="Read More" />
</div>
</div>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-2268991-20");
pageTracker._trackPageview();
} catch(err) {}
</script>
</body>
</html>
My guess is that IE6 is positioning it off the screen, in other words the point you think you are relative to is not the point IE6 is using.
Are you able to make it appear by temporarily setting top/left to 0px and seeing where it shows up?
EDIT - Just looked up some code on one of my sites that does something similar.
I think you need to set position:relative on the parent div then use position:absolute and top/left on the child div.
Try to set position: relative on the parent div of the element you want to position.
It sounds wierd, because usually an absolute element needs a relative parent.
But I found that for older versions of IE, if you have a 'disappearing relative div', then making its' parent relative as well might solve you some problems.
try removing the {left: -720px;} and use a conditional stylesheet for IE. also try giving position relative to the parent of #prizedraw-fliemore