Search Results

Search found 922 results on 37 pages for 'h2'.

Page 4/37 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • how to use javascript to change div backgroundColor

    - by lanqy
    The html below: <div id="catestory"> <div class="content"> <h2>some title here</h2> <p>some content here</p> </div> <div class="content"> <h2>some title here</h2> <p>some content here</p> </div> <div class="content"> <h2>some title here</h2> <p>some content here</p> </div> </div> when mouseover the content of div then it's backgroundColor and the h2(inside this div) backgroundColor change(just like the css :hover) I know this can use css (:hover) to do this in modern browser but IE6 does't work how to use javascript(not jquery or other js framework) to do this? Edit:how to change the h2 backgroundColor too

    Read the article

  • jQuery prevAll displaying text in backward ordering

    - by SoulieBaby
    hi all, I'm trying to use jQuery to get all the paragraphs before the first h2 tag in my content. Here's the code I'm using: $(".content").find("h2:first").prevAll().text() Which is grabbing the content, although it's displaying it in backwards order. Example content: <div class="content"> <p>paragraph 1</p> <p>paragraph 2</p> <p>paragraph 3</p> <h2>First h2 tag</h2> <p>paragraph 4</p> <p>paragraph 5</p> <p>paragraph 6</p> <h2>Second h2 tag</h2> </div> The above code is outputting: <p>paragraph 3</p> <p>paragraph 2</p> <p>paragraph 1</p> Is there any way of reversing this, so it's in the correct order? I have tried using nextAll using different codes, but it seems to grab all of my content, or not work at all lol

    Read the article

  • CSS: "AND" and + operator?

    - by de.vina
    I want to put a space after all the headers using CSS. Like this: if h1 = add a space after else if h1 + h2 = add a space after also but no space in between This is my HTML code <article> <h1>Title 1</h1> ... </article> <article> <h1>Title 1</h1> <h2>Title 2</h2> ... </article> For the CSS h1, h2 { padding-bottom: 20px; } The problem is, there is a space also between h1 and h2. I tried this code below but only those articles with h1 and h2 have a space after. h1 + h2 { padding-bottom: 20px;} Is there a way to do this? Or I should just use the h1 + h2 in CSS and add < br for h1 only?

    Read the article

  • Transpose matrix-style table to 3 columns in Excel

    - by polarbear2k
    I have a matrix-style table in excel where B1:Z1 are column headings and A2:A99 are row headings. I would like to convert this table to a 3 column table (column heading, row heading, cell value). It does not matter in what order the new table is. A B C D A B C A B C 1 H1 H2 H3 1 H1 R1 V1 1 H1 R1 V1 2 R1 V1 V2 V3 => 2 H1 R2 V4 or 2 H2 R1 V2 3 R2 V4 V5 V6 3 H1 R3 V7 3 H3 R1 V3 4 R3 V7 V8 V9 4 H2 R1 V2 4 H1 R2 V4 5 H2 R2 V5 5 H2 R2 V5 6 H2 R3 V8 6 H3 R2 V6 7 H3 R1 V3 7 H1 R3 V7 8 H3 R2 V6 8 H2 R3 V8 9 H3 R3 V9 9 H3 R3 V8 I've been playing around with the OFFSET function to create the whole table but I feel like a combination of TRANSPOSE and V/HLOOKUP is required. Thanks EDIT I have managed to come up with the correct formulas. If the data is in Sheet1 like in my example above, the formulas go in Sheet2: [A1] =IF(ROW() <= COUNTA(Sheet1!$B$1:$Z$1)*COUNTA(Sheet1!$A$2:$A$99), OFFSET(Sheet1!$A$1,0,IF(MOD(ROW(),COUNTA(Sheet1!$B$1:$Z$1))=0,COUNTA(Sheet1!$B$1:$Z$1),MOD(ROW(),COUNTA(Sheet1!$B$1:$Z$1)))),"") [B1] =IF(ROW() <= COUNTA(Sheet1!$B$1:$Z$1)*COUNTA(Sheet1!$A$2:$A$99),OFFSET(Sheet1!$A$1,IF(MOD(ROW(),COUNTA(Sheet1!$A$2:$A$99))=0,COUNTA(Sheet1!$A$2:$A$99),MOD(ROW(),COUNTA(Sheet1!$A$2:$A$99))),0),"") [C1] =IF(ROW() <= COUNTA(Sheet1!$B$1:$Z$1)*COUNTA(Sheet1!$A$2:$A$99),OFFSET(Sheet1!$A$1,IF(MOD(ROW(),COUNTA(Sheet1!$A$2:$A$99))=0,COUNTA(Sheet1!$A$2:$A$99),MOD(ROW(),COUNTA(Sheet1!$A$2:$A$99))),IF(MOD(ROW(),COUNTA(Sheet1!$B$1:$Z$1))=0,COUNTA(Sheet1!$B$1:$Z$1),MOD(ROW(),COUNTA(Sheet1!$B$1:$Z$1)))),"") The formulas are limited to B1:Z1 for the headings and A2:A99 for the rows (these can be increased to their maximums if required). The COUNTA() formula returns the number of cells that actually have values, which limits the number of rows returned to headings*rows. Otherwise the formulas would could go on for infinity because of the MOD function.

    Read the article

  • Help with Collapse and Expand Accordion at same time using JQuery (demo)

    - by Evan
    I'm stuck on an Expand/Collapse accordion using JQuery. After the initial headline is clicked and it expands, if you click to another headline it will collapse the former headline completely FIRST then it will expand the headline you clicked. This collapse first then expand second technique is very distracting and what should happen is as the headline is expanding it should collapse the initial headline. What am I missing? You can experience a demo here: http://media.apus.edu/it/evan-testing/accordion.htm Below is all my work Javascript <script src="http://www.apus.edu/bin/l/y/jquery-1.3.2.min.js" type="text/javascript"></script> <script type="text/javascript"> //<!-- $(document).ready(function() { $(".accordian>li.expanded").removeClass("expanded"); $(".accordian>li h2").addClass("jse").click(function() { var doOpen = !$(this).parent().hasClass('expanded'); var openContainers = $(".accordian>li.expanded").length>0; var targetNode = this; if(openContainers) { $(".accordian>li.expanded h2") .parent() .removeClass('expanded') .end() .nextAll() .slideUp(100,function(){ if($(".accordian>li.expanded").length==0) performOpen(doOpen,targetNode); }); } else { performOpen(doOpen,targetNode); } // if containers are open, proceed on callback // else proceed immediately }).nextAll().slideUp(100); }); function performOpen(doOpen,whichNode) { if(doOpen) { $('html,body').animate({scrollTop: $(whichNode).offset().top}, 1000); //target code $(whichNode).nextAll().slideDown(100).parent().addClass('expanded'); } } //--> </script> CSS <style> .accordian { list-style : none; padding : 0px; margin : 0px; font-size : 12px; } .accordian li { list-style : none; padding : 0px; margin : 0px; } .accordian li a:hover { text-decoration : underline; } .accordian li h2 { cursor : auto; text-decoration : none; padding : 0px 0px 4px 22px; } .accordian li h2.jse { background-image : url(http://www.apus.edu/bin/m/p/toggle_arrow.gif); background-position : 4px -35px; background-repeat : no-repeat; } .accordian li h2:hover { cursor : pointer; text-decoration : underline; } .accordian li li { margin-bottom : 5px; margin-left : 0px; margin-top : 0px; padding : 0px; } .accordian li p { display : block; padding-top : 0px; padding-bottom : 15px; padding-left : 10px; margin-left : 30px; margin-top : 0px; } .accordian li ul { margin-bottom : 30px; margin-top : 0px; padding-top : 0px; padding-left : 0px; margin-left : 0px; } .accordian li.expanded h2.jse { background-position : 4px -5px; } .accordianContainer { margin-top : 0px; padding-top : 0px; } .accordianContainer h2 { padding : 3px; } .accordian_nolist { list-style : none; } </style> HTML <table height="120"><tr><td>&nbsp;</td></tr></table> <div class="accordianContainer"> <ul class="accordian"> <li><h2>Title 1 Goes here - Example</h2> <ul><li> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> </li></ul> </li> </ul> </div> <div class="accordianContainer"> <ul class="accordian"> <li><h2>Title 2 Goes here - Example</h2> <ul><li> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> </li></ul> </li> </ul> </div> <div class="accordianContainer"> <ul class="accordian"> <li><h2>Title 3 Goes here - Example</h2> <ul><li> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> </li></ul> </li> </ul> </div> <div class="accordianContainer"> <ul class="accordian"> <li><h2>Title 4 Goes here - Example</h2> <ul><li> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> </li></ul> </li> </ul> </div> <div class="accordianContainer"> <ul class="accordian"> <li><h2>Title 5 Goes here - Example</h2> <ul><li> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> this is where content goes<BR>this is where content goes<BR>this is where content goes<BR> </li></ul> </li> </ul> </div>

    Read the article

  • CSS text-decoration rule ignored

    - by Ferdy
    I have found similar questions to mine but none of the suggestions seems to apply to my situation, so here goes... I have a webpage with a buch of images on them. Each image has a title which in markup is between h2 tags. The title is a link, so the resulting markup is like this: <ul class="imagelist"> <li> <a href=""><h2>Title 1</h2></a> <a href=""><img src="" /></a> </li> <li> Image 2, etc... </li> </ul> All I want is for the title links to not be underlined. I tried to address this like this: .imagelist li a h2 { color:#333; text-decoration:none; } It completely ignores the text-decoration rule, yet respects the color rule. From other questions I learned that this could be because a child element cannot overrule the text-decoration of any of its parents. So, I went looking for the parent elements to see if any explicit text-decoration rules are applied. I found none. This is driving me crazy, any help? For the sake of completeness, here is the Firebug CSS output, which shows the full inheritance and such. Probably more than you want, but I cannot see anything conflicting here. .imagelist li a h2 { color:#333333; text-decoration:none; } main.css (line 417) h2 { font-size:14px; } main.css (line 40) h1, h2, h3, h4, h5, h6 { display:block; font-weight:bold; margin-bottom:10px; } main.css (line 38) h1, h2, h3, h4, h5, h6 { font-size:100%; font-weight:normal; } reset-min.css (line 7) body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, textarea, p, blockquote, th, td { margin:0; padding:0; } reset-min.css (line 7) Inherited froma /apps/ju...mage/745 a { color:#0063E2; } main.css (line 55) Inherited fromli .imagelist li { list-style-type:none; } main.css (line 411) li { list-style:none outside none; } reset-min.css (line 7) Inherited fromul.imagelist .imagelist { border-collapse:collapse; font-size:9px; } main.css (line 410) Inherited frombody body, form { color:#333333; font:12px arial,helvetica,clean,sans-serif; } main.css (line 36) Inherited fromhtml html { color:#000000;

    Read the article

  • jQuery toggling divs, expand collapse all and keep first item selected when page loads

    - by hollyb
    Hi, I have a question about some functionality I'm trying to add to my jQuery to enable a button or text to expand/contract all the divs on click... and I'd like to figure out how to keep the first div open when the page loads. Here is the jQuery: (document).ready(function(){ //Hides containers on load $(".toggle_container").hide(); //Switch "Open" and "Close" state on click $("h2.trigger").toggle(function(){ $(this).addClass("active"); }, function () { $(this).removeClass("active"); }); //Slide up and down on click $("h2.trigger").click(function(){ $(this).next(".toggle_container").slideToggle("slow"); }); }); And the css: // uses a background image with an on (+) and off (-) state stacked on top of each other h2.trigger { background: url(buttonBG.gif) no-repeat;height: 46px;line-height: 46px;width: 300px;font-size: 2em;font-weight: normal;} h2.trigger a {color: #fff;text-decoration: none; display: block;} h2.active {background-position: left bottom;} .toggle_container { overflow: hidden; } .toggle_container .block {padding: 20px;} And the html <h2 class="trigger"><a href="#">Heading</a></h2> <div class="toggle_container"> <div class="block">Stuff goes here</div> </div> <h2 class="trigger"><a href="#">Heading 2</a></h2> <div class="toggle_container"> <div class="block">Stuff goes here</div> </div> So it works great and looks great. However, when I try to get it to keep the first instance open, the background image that should adjust show the (-) state doesn't change. The code I used to this was: $(".toggle_container:first").show(); So, my question is, does anyone know of an easier way to show the first instance of this as open without having to created specials rules/class for the first item? Also, any ideas about how to make an open all/close all link? Thanks!

    Read the article

  • jquery show/hide/toggle etc.

    - by Ray
    JQUERY: $("li h2").click(function() { $(this).toggleClass("active").siblings().removeClass("active"); $(this).next("div").slideToggle("fast").siblings("div").slideUp("fast"); }); HTML: <ul> <li> <h2>headingA</h2> <div>contentA</div> <h2>headingB</h2> <div>contentB</div> </li> </ul> NOTES: Bascially I'd want: when click on h2 show the div next to it and hide all others, not only show/hide toggle as well. thanks!

    Read the article

  • Mandelbrot set not displaying properly

    - by brainydexter
    I am trying to render mandelbrot set using glsl. I'm not sure why its not rendering the correct shape. Does the mandelbrot calculation require values to be within a range for the (x,y) [ or (real, imag) ] ? Here is a screenshot: I render a quad as follows: float w2 = 6; float h2 = 5; glBegin(GL_QUADS); glVertex3f(-w2, h2, 0.0); glVertex3f(-w2, -h2, 0.0); glVertex3f(w2, -h2, 0.0); glVertex3f(w2, h2, 0.0); glEnd(); My vertex shader: varying vec3 Position; void main(void) { Position = gl_Vertex.xyz; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; } My fragment shader (where all the meat is): uniform float MAXITERATIONS; varying vec3 Position; void main (void) { float zoom = 1.0; float centerX = 0.0; float centerY = 0.0; float real = Position.x * zoom + centerX; float imag = Position.y * zoom + centerY; float r2 = 0.0; float iter; for(iter = 0.0; iter < MAXITERATIONS && r2 < 4.0; ++iter) { float tempreal = real; real = (tempreal * tempreal) + (imag * imag); imag = 2.0 * real * imag; r2 = (real * real) + (imag * imag); } vec3 color; if(r2 < 4.0) color = vec3(1.0); else color = vec3( iter / MAXITERATIONS ); gl_FragColor = vec4(color, 1.0); }

    Read the article

  • Multiple TOC with MediaWiki using section headings in single page

    - by user1704043
    I'm running my own installation of MediaWiki, which has been great! I haven't been able to find the answer to this small problem in any post, how to, etc. Here's the setup: Article TOC (limited to showing only H1 and H2) ==H1== ===H2=== ====H3==== ====H3==== I don't want the H3 to show up on the main table of contents, because it would make the list very long. Instead, under the H2, I would like to display another TOC with all the H3's under that listing. From my understanding, you cannot have multiple table of contents on a single page. I've thought about making a template for each H2 that has the H3 links, but that seems like it duplicates a lot of work and creates loads of pages. I'd love a template that sucks all subsection names and spits them out, but I don't see how to do that. Alternatively, is there a way to enable multiple TOCs in a custom install of MediaWiki that I'm missing? Even that would get closer to what I'm trying to do.

    Read the article

  • GalleryView Jquery

    - by kwek-kwek
    I am trying to implement this JqueryGallery to my website(big gray box). Now my problem is that the images doesn't appear. here is my header code: <link href="css/galleryview.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script> <script type="text/javascript" src="js/jquery.easing.1.3.js"></script> <script type="text/javascript" src="js/jquery.galleryview-2.1.1.js"></script> <script type="text/javascript" src="js/jquery.timers-1.2.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('#photos').galleryView({ panel_width: 655, panel_height: 336, transition_speed: 1500, transition_interval: 5000, nav_theme: 'dark', border: '1px solid white', pause_on_hover: true, }); }); </script> Here is my gallery code: <div id="photos" class="galleryview"> <div class="panel"> <img src="http://spaceforaname.com/img/gallery/01.jpg" /> <div class="panel-overlay"> <h2>Effet du soleil sur le paysage</h2> <p>Photo by <a href="http://www.sxc.hu/profile/tomharry" target="_blank">tomharry</a>. View full-size photo <a href="http://www.sxc.hu/photo/158829" target="_blank">here</a>.</p> </div> </div> <div class="panel"> <img src="http://spaceforaname.com/img/gallery/02.jpg" /> <div class="panel-overlay"> <h2>Eden</h2> <p>Photo by <a href="http://www.sxc.hu/profile/emsago" target="_blank">emsago</a>. View full-size photo <a href="http://www.sxc.hu/photo/152865" target="_blank">here</a>.</p> </div> </div> <div class="panel"> <img src="http://spaceforaname.com/img/gallery/03.jpg" /> <div class="panel-overlay"> <h2>Snail on the Corn</h2> <p>Photo by <a href="http://www.sxc.hu/profile/baines" target="_blank">baines</a>. View full-size photo <a href="http://www.sxc.hu/photo/34453" target="_blank">here</a>.</p> </div> </div> <div class="panel"> <img src="http://spaceforaname.com/img/gallery/04.jpg" /> <div class="panel-overlay"> <h2>Flowers</h2> <p>Photo by <a href="http://www.sxc.hu/profile/jazza" target="_blank">jazza</a>. View full-size photo <a href="http://www.sxc.hu/photo/990169" target="_blank">here</a>.</p> </div> </div> <div class="panel"> <img src="http://spaceforaname.com/img/gallery/06.jpg" /> <div class="panel-overlay"> <h2>Alone Beach 2B</h2> <p>Photo by <a href="http://www.sxc.hu/profile/sgursozlu" target="_blank">sgursozlu</a>. View full-size photo <a href="http://www.sxc.hu/photo/738279" target="_blank">here</a>.</p> </div> </div> </div>

    Read the article

  • Get Two row with multiple column in asp.net c#

    - by Gaurav Naik
    How to get data from database with two rows and multiple column with seperator will be there after the 1 row end as an example: <div class="_thum_bar"> <div class="box1"> <div class="_t1_box"><a href="#!/condom_details"><img src="images/pack/pack1.png" border="0"></a></div> <div class="_t2_box"> <h1>Dotted Condom</h1> <p>Dotted condoms for additional friction. Pure ecstasy makes this a KamaSutra all time favourite.</p> <h2><a href="#!/condom_details">Add to cart</a></h2> </div> </div> <div class="box2"> <div class="_t1_box"><a href="#!/condom_details"><img src="images/pack/pack1.png" border="0"></a></div> <div class="_t2_box"> <h1>Dotted Condom</h1> <p>Dotted condoms for additional friction. Pure ecstasy makes this a KamaSutra all time favourite.</p> <h2><a href="#!/condom_details">Add to cart</a></h2> </div> </div> <div class="box3"> <div class="_t1_box"><a href="#"><img src="images/pack/pack1.png" border="0"></a></div> <div class="_t2_box"> <h1>Dotted Condom</h1> <p>Dotted condoms for additional friction. Pure ecstasy makes this a KamaSutra all time favourite.</p> <h2><a href="#!/condom_details">Add to cart</a></h2> </div> </div> </div> <div class="_t_spacer">&nbsp;</div> <div class="_thum_bar"> <div class="box1"> <div class="_t1_box"><a href="#!/condom_details"><img src="images/pack/pack1.png" border="0"></a></div> <div class="_t2_box"> <h1>Dotted Condom</h1> <p>Dotted condoms for additional friction. Pure ecstasy makes this a KamaSutra all time favourite.</p> <h2><a href="#!/condom_details">Add to cart</a></h2> </div> </div> <div class="box2"> <div class="_t1_box"><a href="#!/condom_details"><img src="images/pack/pack1.png" border="0"></a></div> <div class="_t2_box"> <h1>Dotted Condom</h1> <p>Dotted condoms for additional friction. Pure ecstasy makes this a KamaSutra all time favourite.</p> <h2><a href="#!/condom_details">Add to cart</a></h2> </div> </div> </div> <div class="_t_spacer">&nbsp;</div>

    Read the article

  • issue in property file

    - by devuser
    I want to load the property file when tomcat is starting.so I'm using servletContextListener to do that and i can get values of property file to my web application. But i want to keep the same value after changing the property file once log into web application.But when i change the value of property file and log into system again it change the value to new one.I want to keep the same value that loaded when tomcat was starting.how can i implement this? My coding is as below import javax.servlet.*; import java.io.IOException; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; import java.io.*; import java.util.ResourceBundle; public final class sysProperties implements javax.servlet.ServletContextListener { private static Properties props = new Properties(); private static String file_name = "com/util/contact.properties"; public addSystemProperties() { } public void contextInitialized(ServletContextEvent servletContextEvent) { // Get the context ServletContext servletContext = servletContextEvent.getServletContext(); // Set a context attribute try { // props.load(servletContext.getResourceAsStream(file_name)); props.load(getClass().getClassLoader().getResourceAsStream(file_name)); System.out.println(" Application X is starting"); servletContext.setAttribute("h1",props.getProperty("home.h1")); servletContext.setAttribute("h2",props.getProperty("home.h2")); System.out.println("h1"+servletContext.getAttribute("h1")); System.out.println("h2"+ servletContext.getAttribute("h2")); ; } catch (Exception e) { System.out.println(" Error setting context attribute: " + e.getMessage()); } } public void contextDestroyed(ServletContextEvent servletContextEvent) { // Get the context ServletContext servletContext = servletContextEvent.getServletContext(); // Output the context variable we set earlier System.out.println(" Application X is shutting down"); System.out.println(" Value of h1 is: " + servletContext.getAttribute("h1")); System.out.println(" Value of h2 is: " + servletContext.getAttribute("h2")); // Clean up (not really necessary as the context is being destroyed, but let's be neat) servletContext.removeAttribute(props.getProperty("h1")); servletContext.removeAttribute(props.getProperty("h2")); } }

    Read the article

  • Iterating changes using jQuery?

    - by HipHop-opatamus
    In the HTML below, I would like to copy the "submittedby" beside "message", within the H2 tag: <div class="comment"> <H2 class="threadtitle">Message 1</h2> <span class="submittedby">James</a> </div> <div class="comment"> <H2 class="threadtitle">Message 2</h2> <span class="submittedby">Bill</a> </div> <div class="comment"> <H2 class="threadtitle">Message 3</h2> <div class="submittedby">Phil</a> </div> My current jQuery code is as follows: $(document).ready(function() { $('.submittedby').copy().appendTo('.threadtitle'); }); The problem is this copies EVERY "submittedby" to EVERY "threadtitle". How do I code it so it only copies the "submittedby" from within the same "comment" div? Thanks!

    Read the article

  • center text in div

    - by Son of anarchy
    <div> <div class="left"> <div align="center" class="node"> <div class="nodeText"> <h2 >test</h2> </div> <div class="node"> <h2>test</h2> </div> <div class="node"> <h2>test</h2> </div> <div> I need to center text in div nothing seems to work .left { float:left; width:200px; border:solid 1px black; text-align: center; } .node { height:200px; border:solid 1px black; margin:0 auto; } .nodeText{ vertical-align: middle; } h2{ text-align: center; } Tnxs

    Read the article

  • Using CSS to create three boxes with dividers and text centered within each box

    - by linnse
    I'm trying to figure out the best way to create a row of three boxes (columns), with dividers between boxes 1 and 2, and boxes 2 and 3. The text would need to be centered within each box. h2 { color: #00ADEF; margin-top:0; margin-bottom:0; font-family:Arial, Helvetica, sans-serif; font-size:20px; font-weight:bold; line-height:23px; } p { margin-top:0; } .3colwrapper { width: 930px; margin: 0 auto; } .colbox { float:left; margin: 10px; width: 210px; background:#DDD; padding:10px 40px; } <div class="3colwrapper"> <div class="colbox"><h2>Step One</h2> <p>Sign up</p> </div> <div class="colbox"><h2>Step Two</h2> <p>Verify</p> </div> <div class="colbox"><h2>Step Three</h2> <p>Participate</p> </div> </div> Here's what I've worked up so far: http://cssdesk.com/YyjAr

    Read the article

  • Apache in OS X not displaying localhost nor vhosts correctly

    - by Marcus
    I've encountered a really odd problem in my development environment, and I really can't make any sense of it. It started by a locally developed PHP-site refused to update any content I edited in a file – no text or nothing. So if the document was: <h2>Hello!</h2> and I edited it to <h2>What's wrong?!</h2> it still outputed <h2>Hello!</h2>. I thought is was some kind of cache:ing problem, but no "hard reloads" in the browser nor sudo apachectl -k restart sorted it out. Only a restart of my Mac did finally fix it. Now, a few days later even stranger issues are appearing. I have a LAMP-stack installed via Homebrew, in httpd-vhosts.conf I've set ~/Dev/ as my localhost, and I set up a <VirtualHost *80> for each project ("ServerName projectname.dev" for example). However, what ever files of folder I put in ~/Dev/ have stopped showing up on localhost, and new VirtualHost-directives doesn't work. Three projects + "docs" in the folder: But "localhost" only displays the two older projects...? So, as I've said – I've tried restarting Apache (without errors), clearing browser caches (tried in three browsers, Chrome, Safari and Firefox) and ever rebooting the Mac. Nothing. Any ideas? Running OS X 10.8.5 and Apache 2.2.24.

    Read the article

  • jQuery tabs using radio buttons instead of list navigation

    - by caleb
    I'm following a tutorial to create a simple jquery tabs show/hide content. Wondering if there's a way to re-engineer it to use a list of radio buttons instead of a list? Tutorial here: http://www.sohtanaka.com/web-design/simple-tabs-w-css-jquery/ My js: $(".tab_content").hide(); //Hide all content $("ul.tabs li:first").addClass("active").show(); //Activate first tab $(".tab_content:first").show(); //Show first tab content //On Click Event $("ul.tabs li").click(function() { $("ul.tabs li").removeClass("active"); //Remove any "active" class $(this).addClass("active").children("input[@type=radio]").click(); //Add "active" class to selected tab $(".tab_content").hide(); //Hide all tab content var activeTab = "#" + $(this).children("input").attr("value"); //Find the href attribute value to identify the active tab + content $(activeTab).fadeIn(); //Fade in the active ID content return false; }); My HTML: <ul class="tabs"> <li><input type="radio" name="card" id="one" value="gallery" /> <label for="one">gallery</label></li> <li><input type="radio" name="card" id="two" value="submit" /> <label for="two">submit</label></li> <li><input type="radio" name="card" id="three" value="resources" /> <label for="three">resources</label></li> <li><input type="radio" name="card" id="four" value="contact" /> <label for="four">contact</label></li> </ul> <div class="tab_container"> <div id="gallery" class="tab_content"> <h2>Gallery</h2> </div> <div id="submit" class="tab_content"> <h2>Submit</h2> </div> <div id="resources" class="tab_content"> <h2>Resources</h2> </div> <div id="contact" class="tab_content"> <h2>Contact</h2> </div> </div> I'm able to actively select the radio button within the list, but not activate the actual div.

    Read the article

  • Blackberry Storm - focus issue on bitmap field

    - by SWATI
    in my screen there are 3 managers h1 h2 bmpf = new BitmapField added in order like this as backgroundmanager.add(h1) backgroundmanager.add(bmpf) backgroundmanager.add(h2) add(background manager); protected boolesn navigationClick() { int index1 = h1.getFieldWithFocusIndex(); int index2 = h2.getFieldWithFocusIndex(); return true; } mow i get the focus index of all focussable fields in managers h1 and h2 but i cant get index of the bitnmapfield on focus i need to execute some code on its click what to do

    Read the article

  • How to retrive value in jquery

    - by Wondering
    Hi All, in my js I have a var in which i have stored innerHTML. the var is having value something like <h2>headline<h2> <div>....</div> ........... Now I want to retrieve value of h2 tag..what I am doing is $(myvar).find("h2").text() but its not working...what should be the exact syntax. Thanks.

    Read the article

  • php and asp problem in uploading

    - by moustafa
    i have an ASP web services to change byte array that given from the client and change it to a file and save it in the web server the code is like this : [WebMethod] public string UploadFile(byte[] f, string fileName) { try { MemoryStream ms = new MemoryStream(f); String path="/myfile/"; String location=HttpContext.Current.Server.MapPath(path); FileStream fs = new FileStream(HttpContext.Current.Server.MapPath(path)+fileName, FileMode.Create); ms.WriteTo(fs); ms.Close(); fs.Close(); return "OK"; } catch (Exception ex) { return ex.Message.ToString(); } } the web services need byte array and file name.. i build the client in php upload.php the code is <html> <body> <form action="action1.php" method="post" enctype="multipart/form-data"> Pilih File Anda: <input type="file" name="myfile" /> <input type="submit" value="Upload" /> </form> </body> <html> and action1.php the code is: <?php require_once('nusoap.php'); $client = new nusoap_client('http://192.168.254.160/testuploadah/FileUploader.asmx?WSDL', 'wsdl','','', '', ''); $err = $client->getError(); if ($err) { echo '<h2>Constructor error</h2><pre>' . $err . '</pre>'; } if(is_uploaded_file($_FILES['myfile']['tmp_name'])){ $uploadFile = $_FILES['myfile']; ////how can read byte array of $uploadFile so i can send to web services??? ////are php only can send array or string ? $params[]->f=??????????????? $params[]->fileName=$_FILES['myfile']['name']; $result = $client->call('UploadFile', $params,'', '', false, true); if ($client->fault) { echo '<h2>Fault</h2><pre>'; print_r($result); echo '</pre>'; } else { //Check for errors $err = $client->getError(); if ($err) { //// Display the error echo '<h2>Error</h2><pre>' . $err . '</pre>'; } else { //// Display the result echo '<h2>Result</h2><pre>'; print_r($result); echo '</pre>'; } } } ?> how can i Send the byte array parameter to the web services,so the web services can started???? i still can resolve this problem,the web services always return an error because i can't send byte array

    Read the article

  • Wordpress post query php custom field conditional

    - by Andy
    Here's the situation: In wordpress I'm trying to reset a post WP_Query so that I can rewrite the post link based on whether or not a custom field exists in the post. I'm trying to give the post a NEW link in the custom field. All I've managed to do here is kill the link entirely. Any and all help is greatly appreciated, I'm pretty green to php. Here's my WP_Query: <?php $recentPosts = new WP_Query(); $recentPosts->query('showposts=3'); ?> <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?> <div <?php post_class() ?> id="post-<?php the_ID(); ?>"> <?php $attribute = the_title_attribute(); $title = the_title(); $key = 'NewPostLink'; $newLink = get_post_meta( $post->ID, $key, TRUE ); if ($newLink != '') { $theLink = get_permalink ($post->ID ); if (has_post_thumbnail()) { $image = get_the_post_thumbnail( $post->ID ); echo '<div class="thumbnailbox"><div class="thumbnail"><a href="'.$theLink.'">'.$image.'</a></div></div>'; echo '<h2><a href="'.$theLink.'" rel="bookmark" title="Permanent Link to '.$attribute.'">'.$title.'</a></h2>'; } else { echo '<h2><a href="'.$theLink.'" rel="bookmark" title="Permanent Link to '.$attribute.'">'.$title.'</a></h2>'; } } else { $theLink = $newLink; if (has_post_thumbnail()) { $image = get_the_post_thumbnail( $post->ID ); echo '<div class="thumbnailbox"><div class="thumbnail"><a href="'.$theLink.'">'.$image.'</a></div></div>'; echo '<h2><a href="'.$theLink.'" rel="bookmark" title="Permanent Link to '.$attribute.'">'.$title.'</a></h2>'; } else { echo '<h2><a href="'.$theLink.'" rel="bookmark" title="Permanent Link to '.$attribute.'">'.$title.'</a></h2>'; } } ?> <small><?php the_time('F jS, Y') ?></small> <div class="entry"> <?php the_excerpt(); ?> </div> </div> <?php endwhile; ?>

    Read the article

  • Minor tweak to this javascript function?

    - by RKS
    I have a script that shows/hides used via onClick. I can get it to show/hide just fine, but I can't get it to show/'hide everything else'. So what I get is a bunch of open containers when I really want just the one. Javascript: <script> function showfields(fields){ if(document.getElementById(fields).style.display=='none'){ document.getElementById(fields).style.display='block'; } else{ document.getElementById(fields).style.display = 'none'; } } </script> HTML: <div id="hidden" class="steps" style="display: block;"> <div class="section" style="margin-right: 10px;"> <h2>Something</h2> </div> <button class="continue dropdown" id="showLink" onClick="showfields('hidden2');return false;" href="#">Continue</button> </div> <div id="hidden2" class="steps" style="display: block;"> <div class="section" style="margin-right: 10px;"> <h2>Something2</h2> </div> <button class="continue dropdown" id="showLink" onClick="showfields('hidden3');return false;" href="#">Continue</button> </div> <div id="hidden3" class="steps" style="display: block;"> <div class="section" style="margin-right: 10px;"> <h2>Something3</h2> </div> <button class="continue dropdown" id="showLink" onClick="showfields('hidden3');return false;" href="#">Continue</button> </div> <div id="hidden4" class="steps" style="display: block;"> <div class="section" style="margin-right: 10px;"> <h2>Something4</h2> </div> <button class="continue dropdown" id="showLink" onClick="showfields('hidden4');return false;" href="#">Continue</button> </div> Thanks

    Read the article

  • Why can't I use the return from an insertAfter as a regular jQuery object?

    - by joachim
    I'm trying to insert a link after form elements to clear them. This demo code with headings doesn't work: h2 = $('h2'); clickytest = $('click me').insertAfter(h2).click(function() { $(this).append('foo'); }); But this does: clickytest = $('click me').insertAfter(h2); $('a.clicky').click(function() { $(this).append('foo'); }); The only difference is I've gone back and re-selected the new elements, rather than use what insertAfter returns. If on the other hand there is only one H2 in the whole document, then the first version works. What's going on? I've tried playing with each() but I'm not sure exactly what jQuery is doing here.

    Read the article

  • An Introduction to jQuery Templates

    - by Stephen Walther
    The goal of this blog entry is to provide you with enough information to start working with jQuery Templates. jQuery Templates enable you to display and manipulate data in the browser. For example, you can use jQuery Templates to format and display a set of database records that you have retrieved with an Ajax call. jQuery Templates supports a number of powerful features such as template tags, template composition, and wrapped templates. I’ll concentrate on the features that I think that you will find most useful. In order to focus on the jQuery Templates feature itself, this blog entry is server technology agnostic. All the samples use HTML pages instead of ASP.NET pages. In a future blog entry, I’ll focus on using jQuery Templates with ASP.NET Web Forms and ASP.NET MVC (You can do some pretty powerful things when jQuery Templates are used on the client and ASP.NET is used on the server). Introduction to jQuery Templates The jQuery Templates plugin was developed by the Microsoft ASP.NET team in collaboration with the open-source jQuery team. While working at Microsoft, I wrote the original proposal for jQuery Templates, Dave Reed wrote the original code, and Boris Moore wrote the final code. The jQuery team – especially John Resig – was very involved in each step of the process. Both the jQuery community and ASP.NET communities were very active in providing feedback. jQuery Templates will be included in the jQuery core library (the jQuery.js library) when jQuery 1.5 is released. Until jQuery 1.5 is released, you can download the jQuery Templates plugin from the jQuery Source Code Repository or you can use jQuery Templates directly from the ASP.NET CDN. The documentation for jQuery Templates is already included with the official jQuery documentation at http://api.jQuery.com. The main entry for jQuery templates is located under the topic plugins/templates. A Basic Sample of jQuery Templates Let’s start with a really simple sample of using jQuery Templates. We’ll use the plugin to display a list of books stored in a JavaScript array. Here’s the complete code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html > <head> <title>Intro</title> <link href="0_Site.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="pageContent"> <h1>ASP.NET Bookstore</h1> <div id="bookContainer"></div> </div> <script id="bookTemplate" type="text/x-jQuery-tmpl"> <div> <img src="BookPictures/${picture}" alt="" /> <h2>${title}</h2> price: ${formatPrice(price)} </div> </script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js"></script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script> <script type="text/javascript"> // Create an array of books var books = [ { title: "ASP.NET 4 Unleashed", price: 37.79, picture: "AspNet4Unleashed.jpg" }, { title: "ASP.NET MVC Unleashed", price: 44.99, picture: "AspNetMvcUnleashed.jpg" }, { title: "ASP.NET Kick Start", price: 4.00, picture: "AspNetKickStart.jpg" }, { title: "ASP.NET MVC Unleashed iPhone", price: 44.99, picture: "AspNetMvcUnleashedIPhone.jpg" }, ]; // Render the books using the template $("#bookTemplate").tmpl(books).appendTo("#bookContainer"); function formatPrice(price) { return "$" + price.toFixed(2); } </script> </body> </html> When you open this page in a browser, a list of books is displayed: There are several things going on in this page which require explanation. First, notice that the page uses both the jQuery 1.4.4 and jQuery Templates libraries. Both libraries are retrieved from the ASP.NET CDN: <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js"></script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script> You can use the ASP.NET CDN for free (even for production websites). You can learn more about the files included on the ASP.NET CDN by visiting the ASP.NET CDN documentation page. Second, you should notice that the actual template is included in a script tag with a special MIME type: <script id="bookTemplate" type="text/x-jQuery-tmpl"> <div> <img src="BookPictures/${picture}" alt="" /> <h2>${title}</h2> price: ${formatPrice(price)} </div> </script> This template is displayed for each of the books rendered by the template. The template displays a book picture, title, and price. Notice that the SCRIPT tag which wraps the template has a MIME type of text/x-jQuery-tmpl. Why is the template wrapped in a SCRIPT tag and why the strange MIME type? When a browser encounters a SCRIPT tag with an unknown MIME type, it ignores the content of the tag. This is the behavior that you want with a template. You don’t want a browser to attempt to parse the contents of a template because this might cause side effects. For example, the template above includes an <img> tag with a src attribute that points at “BookPictures/${picture}”. You don’t want the browser to attempt to load an image at the URL “BookPictures/${picture}”. Instead, you want to prevent the browser from processing the IMG tag until the ${picture} expression is replaced by with the actual name of an image by the jQuery Templates plugin. If you are not worried about browser side-effects then you can wrap a template inside any HTML tag that you please. For example, the following DIV tag would also work with the jQuery Templates plugin: <div id="bookTemplate" style="display:none"> <div> <h2>${title}</h2> price: ${formatPrice(price)} </div> </div> Notice that the DIV tag includes a style=”display:none” attribute to prevent the template from being displayed until the template is parsed by the jQuery Templates plugin. Third, notice that the expression ${…} is used to display the value of a JavaScript expression within a template. For example, the expression ${title} is used to display the value of the book title property. You can use any JavaScript function that you please within the ${…} expression. For example, in the template above, the book price is formatted with the help of the custom JavaScript formatPrice() function which is defined lower in the page. Fourth, and finally, the template is rendered with the help of the tmpl() method. The following statement selects the bookTemplate and renders an array of books using the bookTemplate. The results are appended to a DIV element named bookContainer by using the standard jQuery appendTo() method. $("#bookTemplate").tmpl(books).appendTo("#bookContainer"); Using Template Tags Within a template, you can use any of the following template tags. {{tmpl}} – Used for template composition. See the section below. {{wrap}} – Used for wrapped templates. See the section below. {{each}} – Used to iterate through a collection. {{if}} – Used to conditionally display template content. {{else}} – Used with {{if}} to conditionally display template content. {{html}} – Used to display the value of an HTML expression without encoding the value. Using ${…} or {{= }} performs HTML encoding automatically. {{= }}-- Used in exactly the same way as ${…}. {{! }} – Used for displaying comments. The contents of a {{!...}} tag are ignored. For example, imagine that you want to display a list of blog entries. Each blog entry could, possibly, have an associated list of categories. The following page illustrates how you can use the { if}} and {{each}} template tags to conditionally display categories for each blog entry:   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>each</title> <link href="1_Site.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="blogPostContainer"></div> <script id="blogPostTemplate" type="text/x-jQuery-tmpl"> <h1>${postTitle}</h1> <p> ${postEntry} </p> {{if categories}} Categories: {{each categories}} <i>${$value}</i> {{/each}} {{else}} Uncategorized {{/if}} </script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js"></script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script> <script type="text/javascript"> var blogPosts = [ { postTitle: "How to fix a sink plunger in 5 minutes", postEntry: "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.", categories: ["HowTo", "Sinks", "Plumbing"] }, { postTitle: "How to remove a broken lightbulb", postEntry: "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.", categories: ["HowTo", "Lightbulbs", "Electricity"] }, { postTitle: "New associate website", postEntry: "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna." } ]; // Render the blog posts $("#blogPostTemplate").tmpl(blogPosts).appendTo("#blogPostContainer"); </script> </body> </html> When this page is opened in a web browser, the following list of blog posts and categories is displayed: Notice that the first and second blog entries have associated categories but the third blog entry does not. The third blog entry is “Uncategorized”. The template used to render the blog entries and categories looks like this: <script id="blogPostTemplate" type="text/x-jQuery-tmpl"> <h1>${postTitle}</h1> <p> ${postEntry} </p> {{if categories}} Categories: {{each categories}} <i>${$value}</i> {{/each}} {{else}} Uncategorized {{/if}} </script> Notice the special expression $value used within the {{each}} template tag. You can use $value to display the value of the current template item. In this case, $value is used to display the value of each category in the collection of categories. Template Composition When building a fancy page, you might want to build a template out of multiple templates. In other words, you might want to take advantage of template composition. For example, imagine that you want to display a list of products. Some of the products are being sold at their normal price and some of the products are on sale. In that case, you might want to use two different templates for displaying a product: a productTemplate and a productOnSaleTemplate. The following page illustrates how you can use the {{tmpl}} tag to build a template from multiple templates:   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Composition</title> <link href="2_Site.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="pageContainer"> <h1>Products</h1> <div id="productListContainer"></div> <!-- Show list of products using composition --> <script id="productListTemplate" type="text/x-jQuery-tmpl"> <div> {{if onSale}} {{tmpl "#productOnSaleTemplate"}} {{else}} {{tmpl "#productTemplate"}} {{/if}} </div> </script> <!-- Show product --> <script id="productTemplate" type="text/x-jQuery-tmpl"> ${name} </script> <!-- Show product on sale --> <script id="productOnSaleTemplate" type="text/x-jQuery-tmpl"> <b>${name}</b> <img src="images/on_sale.png" alt="On Sale" /> </script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js"></script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script> <script type="text/javascript"> var products = [ { name: "Laptop", onSale: false }, { name: "Apples", onSale: true }, { name: "Comb", onSale: false } ]; $("#productListTemplate").tmpl(products).appendTo("#productListContainer"); </script> </div> </body> </html>   In the page above, the main template used to display the list of products looks like this: <script id="productListTemplate" type="text/x-jQuery-tmpl"> <div> {{if onSale}} {{tmpl "#productOnSaleTemplate"}} {{else}} {{tmpl "#productTemplate"}} {{/if}} </div> </script>   If a product is on sale then the product is displayed with the productOnSaleTemplate (which includes an on sale image): <script id="productOnSaleTemplate" type="text/x-jQuery-tmpl"> <b>${name}</b> <img src="images/on_sale.png" alt="On Sale" /> </script>   Otherwise, the product is displayed with the normal productTemplate (which does not include the on sale image): <script id="productTemplate" type="text/x-jQuery-tmpl"> ${name} </script>   You can pass a parameter to the {{tmpl}} tag. The parameter becomes the data passed to the template rendered by the {{tmpl}} tag. For example, in the previous section, we used the {{each}} template tag to display a list of categories for each blog entry like this: <script id="blogPostTemplate" type="text/x-jQuery-tmpl"> <h1>${postTitle}</h1> <p> ${postEntry} </p> {{if categories}} Categories: {{each categories}} <i>${$value}</i> {{/each}} {{else}} Uncategorized {{/if}} </script>   Another way to create this template is to use template composition like this: <script id="blogPostTemplate" type="text/x-jQuery-tmpl"> <h1>${postTitle}</h1> <p> ${postEntry} </p> {{if categories}} Categories: {{tmpl(categories) "#categoryTemplate"}} {{else}} Uncategorized {{/if}} </script> <script id="categoryTemplate" type="text/x-jQuery-tmpl"> <i>${$data}</i> &nbsp; </script>   Using the {{each}} tag or {{tmpl}} tag is largely a matter of personal preference. Wrapped Templates The {{wrap}} template tag enables you to take a chunk of HTML and transform the HTML into another chunk of HTML (think easy XSLT). When you use the {{wrap}} tag, you work with two templates. The first template contains the HTML being transformed and the second template includes the filter expressions for transforming the HTML. For example, you can use the {{wrap}} template tag to transform a chunk of HTML into an interactive tab strip: When you click any of the tabs, you see the corresponding content. This tab strip was created with the following page: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Wrapped Templates</title> <style type="text/css"> body { font-family: Arial; background-color:black; } .tabs div { display:inline-block; border-bottom: 1px solid black; padding:4px; background-color:gray; cursor:pointer; } .tabs div.tabState_true { background-color:white; border-bottom:1px solid white; } .tabBody { border-top:1px solid white; padding:10px; background-color:white; min-height:400px; width:400px; } </style> </head> <body> <div id="tabsView"></div> <script id="tabsContent" type="text/x-jquery-tmpl"> {{wrap "#tabsWrap"}} <h3>Tab 1</h3> <div> Content of tab 1. Lorem ipsum dolor <b>sit</b> amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. </div> <h3>Tab 2</h3> <div> Content of tab 2. Lorem ipsum dolor <b>sit</b> amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. </div> <h3>Tab 3</h3> <div> Content of tab 3. Lorem ipsum dolor <b>sit</b> amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. </div> {{/wrap}} </script> <script id="tabsWrap" type="text/x-jquery-tmpl"> <div class="tabs"> {{each $item.html("h3", true)}} <div class="tabState_${$index === selectedTabIndex}"> ${$value} </div> {{/each}} </div> <div class="tabBody"> {{html $item.html("div")[selectedTabIndex]}} </div> </script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js"></script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script> <script type="text/javascript"> // Global for tracking selected tab var selectedTabIndex = 0; // Render the tab strip $("#tabsContent").tmpl().appendTo("#tabsView"); // When a tab is clicked, update the tab strip $("#tabsView") .delegate(".tabState_false", "click", function () { var templateItem = $.tmplItem(this); selectedTabIndex = $(this).index(); templateItem.update(); }); </script> </body> </html>   The “source” for the tab strip is contained in the following template: <script id="tabsContent" type="text/x-jquery-tmpl"> {{wrap "#tabsWrap"}} <h3>Tab 1</h3> <div> Content of tab 1. Lorem ipsum dolor <b>sit</b> amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. </div> <h3>Tab 2</h3> <div> Content of tab 2. Lorem ipsum dolor <b>sit</b> amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. </div> <h3>Tab 3</h3> <div> Content of tab 3. Lorem ipsum dolor <b>sit</b> amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. </div> {{/wrap}} </script>   The tab strip is created with a list of H3 elements (which represent each tab) and DIV elements (which represent the body of each tab). Notice that the HTML content is wrapped in the {{wrap}} template tag. This template tag points at the following tabsWrap template: <script id="tabsWrap" type="text/x-jquery-tmpl"> <div class="tabs"> {{each $item.html("h3", true)}} <div class="tabState_${$index === selectedTabIndex}"> ${$value} </div> {{/each}} </div> <div class="tabBody"> {{html $item.html("div")[selectedTabIndex]}} </div> </script> The tabs DIV contains all of the tabs. The {{each}} template tag is used to loop through each of the H3 elements from the source template and render a DIV tag that represents a particular tab. The template item html() method is used to filter content from the “source” HTML template. The html() method accepts a jQuery selector for its first parameter. The tabs are retrieved from the source template by using an h3 filter. The second parameter passed to the html() method – the textOnly parameter -- causes the filter to return the inner text of each h3 element. You can learn more about the html() method at the jQuery website (see the section on $item.html()). The tabBody DIV renders the body of the selected tab. Notice that the {{html}} template tag is used to display the tab body so that HTML content in the body won’t be HTML encoded. The html() method is used, once again, to grab all of the DIV elements from the source HTML template. The selectedTabIndex global variable is used to display the contents of the selected tab. Remote Templates A common feature request for jQuery templates is support for remote templates. Developers want to be able to separate templates into different files. Adding support for remote templates requires only a few lines of extra code (Dave Ward has a nice blog entry on this). For example, the following page uses a remote template from a file named BookTemplate.htm: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Remote Templates</title> <link href="0_Site.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="pageContent"> <h1>ASP.NET Bookstore</h1> <div id="bookContainer"></div> </div> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js"></script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script> <script type="text/javascript"> // Create an array of books var books = [ { title: "ASP.NET 4 Unleashed", price: 37.79, picture: "AspNet4Unleashed.jpg" }, { title: "ASP.NET MVC Unleashed", price: 44.99, picture: "AspNetMvcUnleashed.jpg" }, { title: "ASP.NET Kick Start", price: 4.00, picture: "AspNetKickStart.jpg" }, { title: "ASP.NET MVC Unleashed iPhone", price: 44.99, picture: "AspNetMvcUnleashedIPhone.jpg" }, ]; // Get the remote template $.get("BookTemplate.htm", null, function (bookTemplate) { // Render the books using the remote template $.tmpl(bookTemplate, books).appendTo("#bookContainer"); }); function formatPrice(price) { return "$" + price.toFixed(2); } </script> </body> </html>   The remote template is retrieved (and rendered) with the following code: // Get the remote template $.get("BookTemplate.htm", null, function (bookTemplate) { // Render the books using the remote template $.tmpl(bookTemplate, books).appendTo("#bookContainer"); });   This code uses the standard jQuery $.get() method to get the BookTemplate.htm file from the server with an Ajax request. After the BookTemplate.htm file is successfully retrieved, the $.tmpl() method is used to render an array of books with the template. Here’s what the BookTemplate.htm file looks like: <div> <img src="BookPictures/${picture}" alt="" /> <h2>${title}</h2> price: ${formatPrice(price)} </div> Notice that the template in the BooksTemplate.htm file is not wrapped by a SCRIPT element. There is no need to wrap the template in this case because there is no possibility that the template will get interpreted before you want it to be interpreted. If you plan to use the bookTemplate multiple times – for example, you are paging or sorting the books -- then you should compile the template into a function and cache the compiled template function. For example, the following page can be used to page through a list of 100 products (using iPhone style More paging). <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Template Caching</title> <link href="6_Site.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>Products</h1> <div id="productContainer"></div> <button id="more">More</button> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js"></script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script> <script type="text/javascript"> // Globals var pageIndex = 0; // Create an array of products var products = []; for (var i = 0; i < 100; i++) { products.push({ name: "Product " + (i + 1) }); } // Get the remote template $.get("ProductTemplate.htm", null, function (productTemplate) { // Compile and cache the template $.template("productTemplate", productTemplate); // Render the products renderProducts(0); }); $("#more").click(function () { pageIndex++; renderProducts(); }); function renderProducts() { // Get page of products var pageOfProducts = products.slice(pageIndex * 5, pageIndex * 5 + 5); // Used cached productTemplate to render products $.tmpl("productTemplate", pageOfProducts).appendTo("#productContainer"); } function formatPrice(price) { return "$" + price.toFixed(2); } </script> </body> </html>   The ProductTemplate is retrieved from an external file named ProductTemplate.htm. This template is retrieved only once. Furthermore, it is compiled and cached with the help of the $.template() method: // Get the remote template $.get("ProductTemplate.htm", null, function (productTemplate) { // Compile and cache the template $.template("productTemplate", productTemplate); // Render the products renderProducts(0); });   The $.template() method compiles the HTML representation of the template into a JavaScript function and caches the template function with the name productTemplate. The cached template can be used by calling the $.tmp() method. The productTemplate is used in the renderProducts() method: function renderProducts() { // Get page of products var pageOfProducts = products.slice(pageIndex * 5, pageIndex * 5 + 5); // Used cached productTemplate to render products $.tmpl("productTemplate", pageOfProducts).appendTo("#productContainer"); } In the code above, the first parameter passed to the $.tmpl() method is the name of a cached template. Working with Template Items In this final section, I want to devote some space to discussing Template Items. A new Template Item is created for each rendered instance of a template. For example, if you are displaying a list of 100 products with a template, then 100 Template Items are created. A Template Item has the following properties and methods: data – The data associated with the Template Instance. For example, a product. tmpl – The template associated with the Template Instance. parent – The parent template item if the template is nested. nodes – The HTML content of the template. calls – Used by {{wrap}} template tag. nest – Used by {{tmpl}} template tag. wrap – Used to imperatively enable wrapped templates. html – Used to filter content from a wrapped template. See the above section on wrapped templates. update – Used to re-render a template item. The last method – the update() method -- is especially interesting because it enables you to re-render a template item with new data or even a new template. For example, the following page displays a list of books. When you hover your mouse over any of the books, additional book details are displayed. In the following screenshot, details for ASP.NET Kick Start are displayed. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Template Item</title> <link href="0_Site.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="pageContent"> <h1>ASP.NET Bookstore</h1> <div id="bookContainer"></div> </div> <script id="bookTemplate" type="text/x-jQuery-tmpl"> <div class="bookItem"> <img src="BookPictures/${picture}" alt="" /> <h2>${title}</h2> price: ${formatPrice(price)} </div> </script> <script id="bookDetailsTemplate" type="text/x-jQuery-tmpl"> <div class="bookItem"> <img src="BookPictures/${picture}" alt="" /> <h2>${title}</h2> price: ${formatPrice(price)} <p> ${description} </p> </div> </script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4.js"></script> <script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script> <script type="text/javascript"> // Create an array of books var books = [ { title: "ASP.NET 4 Unleashed", price: 37.79, picture: "AspNet4Unleashed.jpg", description: "The most comprehensive book on Microsoft’s new ASP.NET 4.. " }, { title: "ASP.NET MVC Unleashed", price: 44.99, picture: "AspNetMvcUnleashed.jpg", description: "Writing for professional programmers, Walther explains the crucial concepts that make the Model-View-Controller (MVC) development paradigm work…" }, { title: "ASP.NET Kick Start", price: 4.00, picture: "AspNetKickStart.jpg", description: "Visual Studio .NET is the premier development environment for creating .NET applications…." }, { title: "ASP.NET MVC Unleashed iPhone", price: 44.99, picture: "AspNetMvcUnleashedIPhone.jpg", description: "ASP.NET MVC Unleashed for the iPhone…" }, ]; // Render the books using the template $("#bookTemplate").tmpl(books).appendTo("#bookContainer"); // Get compiled details template var bookDetailsTemplate = $("#bookDetailsTemplate").template(); // Add hover handler $(".bookItem").mouseenter(function () { // Get template item associated with DIV var templateItem = $(this).tmplItem(); // Change template to compiled template templateItem.tmpl = bookDetailsTemplate; // Re-render template templateItem.update(); }); function formatPrice(price) { return "$" + price.toFixed(2); } </script> </body> </html>   There are two templates used to display a book: bookTemplate and bookDetailsTemplate. When you hover your mouse over a template item, the standard bookTemplate is swapped out for the bookDetailsTemplate. The bookDetailsTemplate displays a book description. The books are rendered with the bookTemplate with the following line of code: // Render the books using the template $("#bookTemplate").tmpl(books).appendTo("#bookContainer");   The following code is used to swap the bookTemplate and the bookDetailsTemplate to show details for a book: // Get compiled details template var bookDetailsTemplate = $("#bookDetailsTemplate").template(); // Add hover handler $(".bookItem").mouseenter(function () { // Get template item associated with DIV var templateItem = $(this).tmplItem(); // Change template to compiled template templateItem.tmpl = bookDetailsTemplate; // Re-render template templateItem.update(); });   When you hover your mouse over a DIV element rendered by the bookTemplate, the mouseenter handler executes. First, this handler retrieves the Template Item associated with the DIV element by calling the tmplItem() method. The tmplItem() method returns a Template Item. Next, a new template is assigned to the Template Item. Notice that a compiled version of the bookDetailsTemplate is assigned to the Template Item’s tmpl property. The template is compiled earlier in the code by calling the template() method. Finally, the Template Item update() method is called to re-render the Template Item with the bookDetailsTemplate instead of the original bookTemplate. Summary This is a long blog entry and I still have not managed to cover all of the features of jQuery Templates J However, I’ve tried to cover the most important features of jQuery Templates such as template composition, template wrapping, and template items. To learn more about jQuery Templates, I recommend that you look at the documentation for jQuery Templates at the official jQuery website. Another great way to learn more about jQuery Templates is to look at the (unminified) source code.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >