473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

calling div- onclick anchor tag

5
I have 3 anchor (a) tags, all sharing a single div element to act upon. See my html below. Basically, when you click on anchor tag 1, I want it to fill the div with id="fillDiv" with html. When you click the second anchor tag, it should wipe that #fillDiv and replace it with new html. How do I set up such a functions. Here is my attempt

HTML:

Expand|Select|Wrap|Line Numbers
  1. <div>
  2. <a id="a1" href="javascript: changeDiv();">tag1</a>
  3. <a id="a2" href="javascript: changeDiv();">tag2</a>
  4. <a id="a3" href="javascript: changeDiv();">tag3</a>
  5. </div>
  6.  
  7. <div id="fillDiv"></div>
js:

Expand|Select|Wrap|Line Numbers
  1. function changeDiv(){
  2.      if changeDiv().is('#a1'){
  3.          document.getElementById('fillDiv').html('<div>filling 1</div>');
  4.          }
  5.  
  6.      elseif
  7.          changeDiv().is('#a2'){
  8.          document.getElementById('fillDiv').html('<div>filling 2</div>');
  9.          }
  10.  
  11.      elseif
  12.          changeDiv().is('#a3'){
  13.          document.getElementById('fillDiv').html('<div>filling 3</div>');
  14.          }
  15. }
can anyone help?
Sep 18 '14 #1
2 6723
Exequiel
288 256MB
Try this one.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Zick Sample</title>
  6. <script>
  7. function changeDiv(e)
  8. {
  9.     var changeme = document.getElementById('fillDiv');
  10.     changeme.innerHTML = "filling "+e;
  11. }
  12. </script>
  13. </head>
  14.  
  15. <body>
  16. <div>
  17. <a id="a1" href="javascript: changeDiv(1);">tag1</a>
  18. <a id="a2" href="javascript: changeDiv(2);">tag2</a>
  19. <a id="a3" href="javascript: changeDiv(3);">tag3</a>
  20. </div>
  21.  
  22. <div id="fillDiv">filling 1</div>
  23.  
  24. </body>
  25. </html>
Sep 19 '14 #2
ramani
5
thank you its working fine. but, i actually want to append <div> tag to the innerhtml,

i have three different codes something like

Expand|Select|Wrap|Line Numbers
  1. <div class='tableauPlaceholder' style='width: 600px; height: 599px;'><object class='tableauViz' width='600' height='599' style='display:none;'><param name='host_url' value='https%3A%2F%2Fonline.tableausoftware.com%2F' /> <param name='site_root' value='/t/nettscience' /><param name='name' value='Livon/Adwords/renuka.srinivas@nettscience.com/Adgroup' /><param name='tabs' value='yes' /><param name='toolbar' value='yes' /></object></div>
  2.  
  3. so based on the tag onclick the corressponding div code should trigger and share the same place.
  4.  
  5. pls refer the code below,
  6.  
  7. <!DOCTYPE html PUBLIC "-//W3C//DTD&nbsp;XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  8. <html xmlns="http://www.w3.org/1999/xhtml">
  9. <head>
  10. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  11. <title>Zick Sample</title>
  12. <script type='text/javascript' src='https://online.tableausoftware.com/javascripts/api/viz_v1.js'></script>
  13. <script>
  14. function changeDiv(e)
  15. {
  16.     var changeme = document.getElementById('fillDiv');
  17.     changeme.innerHTML = '<div class='tableauPlaceholder' style='width: 600px; height: 599px;'><object class='tableauViz' width='600' height='599' style='display:none;'><param name='host_url' value='https%3A%2F%2Fonline.tableausoftware.com%2F' /> <param name='site_root' value='/t/nettscience' /><param name='name' value='Livon/Adwords/renuka.srinivas@nettscience.com/Adgroup' /><param name='tabs' value='yes' /><param name='toolbar' value='yes' /></object></div>';
  18. }
  19. </script>
  20. </head>
  21.  
  22. <body>
  23. <div>
  24. <a id="a1" href="javascript: changeDiv(1);">tag1</a>
  25. <a id="a2" href="javascript: changeDiv(2);">tag2</a>
  26. <a id="a3" href="javascript: changeDiv(3);">tag3</a>
  27. </div>
  28.  
  29. <div id="fillDiv"></div>
  30.  
  31. </body>
  32. </html>
  33.  
  34.  
  35. the script for your reference,
  36.  
  37. if you run the below code you understand what im trying to solve,
  38.  
  39. <script type='text/javascript' src='https://online.tableausoftware.com/javascripts/api/viz_v1.js'></script><div class='tableauPlaceholder' style='width: 600px; height: 599px;'><object class='tableauViz' width='600' height='599' style='display:none;'><param name='host_url' value='https%3A%2F%2Fonline.tableausoftware.com%2F' /> <param name='site_root' value='/t/nettscience' /><param name='name' value='Livon/Adwords/renuka.srinivas@nettscience.com/Adgroup' /><param name='tabs' value='yes' /><param name='toolbar' value='yes' /></object></div>
Sep 19 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Silmar | last post by:
Hi! In my form I have table which cells contain input objects of type="text" which initially are disabled. I would like to activate them by clicking on them. However because input object does...
8
by: Andrew Poulos | last post by:
I've have a number of DIV tags that contain one image. Each DIV has an onclick event. How can I get the image filename? I just need the filename and not the file path. I was trying to do...
10
by: Eric-Sebastien Lachance | last post by:
Hey there, I decided to just create a 100% height and width div that filled the space over a background header image, and add an onclick event to redirect to the my index... Doesn't seem to work...
2
by: libsfan01 | last post by:
Hi all How do u reference the id (and also now i think about it the name) of the enclosing div tag of a form element such as a button or div tag (without specifying its name)? I've tried:...
3
by: phish.guy | last post by:
How do I call another event's onclick function from a button press? I have stored information dynamically created in a div onclick function that is not accessible directly by the button, but i...
17
by: yawnmoth | last post by:
http://www.frostjedi.com/terra/scripts/demo/this-alert.html http://www.frostjedi.com/terra/scripts/demo/this-alert2.html Why, when you click in the black box, do the alert boxes say different...
5
by: saadkhan | last post by:
i want to a buttin click event when a <div> is clicked. That is when div tag`s onclick event fires, it directs to button click event..... <div id="Div" onclick="????????"> HEADER </div>...
1
by: xdevel1999 | last post by:
Hi why if I have a DIV I can raise an onclick event only on the inner DIVs and not on the whole area? (Firefox does it) <div id="submenu" class="style1"> <div id="item" onclick="alert(444)">...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.