jQuery change elements within div

I'm stuck with this kinda stupid problem. I saw examples of my problem, but it seems I can't find correct loop. In any case, I'll better provide examples:

<table border="1" id="inline" class="<?=$id?>" style="background:none;"> <tr id="border<?=$id?>"> <td rowspan="2" style="max-width:420; width:420" valign="top"> <form id="feedback<?=$id?>" <? if(!$check){?>style="display:none"<? }?>> <textarea cols="40" class="editor" id="editor<?=$id?>" name="editor1" rows="10"><?=$text?></textarea> <table style="background:none"><tr><td><input type="button" value="Save" id="submit<?=$id?>"></td><td><img id="spinner<?=$id?>" height="25" style="display:none"></td></tr></table> </form> <div id="content<?=$id?>"<? if($check){?> style="display:none"<? }?>><?=$text?></div> </td> <td style="border-width:0"> Title:<br> <div id="title_div<?=$id?>"<? if($check){?> style="display:none"<? }?>><?=$title?></div><input type="text" id="title<?=$id?>" value="<?=$title?>"<? if(!$check){?> style="display:none"<? }?>> </td> </tr> <tr> <td style="border-width:0" valign="top"> <div id="uploader<?=$id?>"<? if(!empty($img)){?> style="display:none<? }?>"> <input id="upload<?=$id?>" name="upload" type="file" /> </div> <div id="div_holder<?=$id?>"> <? draw_buttons($id);?> <a title="<?=$title?>" <? if(!empty($img)){?> href="images/people/<?=$img?>"<? }?> id="feedback_img<?=$id?>" class="lightbox"><img border="0"<? if(!empty($img)){?> src="images/people/timthumb.php?src=<?=$img?>&w=200&q=100"<? }else{?> style="display:none"<? }?> id="img_holder<?=$id?>"></a></div><img id="jcrop<?=$id?>" style="display:none" /> </td> </tr> </table>

This is a part of my php script where $id is taken from database. Ids are numeric, so all table ids differ only with a number, eg.:

<tr id="border1"> //next table tr <tr id="border2">

All tables are taken from database and shown within a loop. Ids can be deleted, so their order could be 1,3,4,6 and so on. But there's one hidden table with known $id = 'zero', eg.:

<tr id="borderzero">

There's also div element with id zero, within which shown above table is situated. So my problem is - I need to change id of each element within that div with id zero, eg.:

<tr id="borderzero"> //change to <tr id="border5">

Of course I can just type them one by one, but I'm trying with the .each function, though I fail and I hope I'll get some help. Here's what I came with:

$("div#zero").clone().attr({'id' : feedback_id}).appendTo("#temp_holder").fadeIn('slow'); $('#' + feedback_id + ":not(td)").contents().each(function() { if($("[id*='zero']").length > 0){ var new_id = $(this).attr('id'); new_id = new_id.replace('zero', some_id); $(this).attr({'id' : new_id}); } });

Var feedback_id through ajax taken from database and it's value is last table id +1.

-------------Problems Reply------------

Try replacing this:

if($("[id*='zero']").length > 0)

with this:

if( this.id.match(/zero$/ig) )

Okay I found a way to actually get all the elements. First answer was helpful, thank you, but also had to change .contents() to .find('*'). So the working script looks like this if somebody would require it:

$("div#zero").clone().attr({'id' : feedback_id}).appendTo("#temp_holder").fadeIn('slow');
$('#' + feedback_id + ":not(td)").find('*').each(function() {
if(this.id.match(/zero$/ig)){
var new_id = $(this).attr('id');
new_id = new_id.replace('zero', some_id);
$(this).attr({'id' : new_id});
}
});

Category:jquery Views:0 Time:2011-02-18
Tags: jquery

Related post

  • Jquery: Finding Element In DIV 2011-08-15

    I have the following (basically, schedule_box is the wrapper, and there can be as many client_schedule divs as needed). I have .details hidden by default, and I want the details to show when the down arrow is clicked: <div class="schedule_box">

  • Jquery append element to Div and show/hide on hover 2012-04-28

    I am attempting to use Jquery to append a footer div into another div and have the newly appended footer div display on hover and slowly fade/hide afterwards. This is the code I have come up with so far: <script type="text/javascript"> $('.xg_w

  • Jquery append element to Div and hide on mouseout 2012-04-29

    I am attempting to use Jquery to append a footer div into another div and have the newly appended footer div display on hover and slowly fade/hide afterwards. This is the code I have come up with so far: <script type="text/javascript"> $('.xg_w

  • jQuery: Is there an event that's triggered by data insertion into a HTML element, say div? 2011-07-27

    Say that I have a <div id="notification"> which has empty content to start with. The server will ajaxly inserts some content into it later on. Is there an event that's triggered by this insertion? Thanks. Note I am using jQuery as my js framewo

  • jQuery - Wrap elements after one div and before anotherone 2011-05-10

    I have this html <div class="sbox"> <div class="top-sbox"></div> <h3>Menu</h3> <ul class="subpages"> <li><a href="#">Subpagina</a></li> <li><a href="#">Subpagina</a></li

  • How can I use jQuery to move a div across the screen 2009-02-04

    I need to make multiple divs move from right to left across the screen and stop when it gets to the edge. I have been playing with jQuery lately, and it seem like what I want can be done using that. Does anyone have or know where I can find an exampl

  • jquery UI Tabs using DIV instead of UL for navigation 2009-08-07

    Hi Im a little new to JS and this has got me scratching my head like crazy. I want to use a DIV with a bunch of anchors inside for the navigation instead of the mandatory (I think?) UL. I have found the piece of code that does this, but I can't seem

  • Use jQuery to hide a DIV when the user clicks outside of it 2009-09-10

    I am using this code: $('body').click(function() { $('.form_wrapper').hide(); }); $('.form_wrapper').click(function(event){ event.stopPropagation(); }); And this HTML: <div class="form_wrapper"> <a class="agree" href="javascript:;">I Agre

  • jQuery DOM element creation vs innerHTML 2010-06-12

    While having one of my questions answered, cletus mentioned that when creating elements in jQuery it's better to use direct DOM element creation, instead of innerHTML. I tried googling it but I wasn't able to find a good article with comparisons. I'v

  • jQuery click link find div with matching id scrollTo 2011-02-14

    I am creating a page. I have the following HTML: <ul id="nav"> <li><a href="#section1">Link</a></li> <li><a href="#section2">Link</a></li> <li><a href="#section3">Link</a></li

  • How to use jquery validation plugin on DIV tag 2011-03-21

    I have a form with multiple steps like jquery tabs. My intention is to validate the input text fields within a single tab and only then will the user be able to go to next tab. In the last tab I want to submit the form with all the data from previous

  • Most efficient way to re-use jQuery-selected elements 2011-03-28

    I can imagine the correct answer to this based on theory, but I'm just looking for some confirmation. I'm wondering what the most efficient way to re-use a jQuery-selected element is. For example: $('#my_div').css('background','red'); //some other co

  • JQuery UI elements not displaying within Jquery loaded partial view 2011-04-23

    So, I've researched this quite abit on stack but am not finding anything related to my specific issue. I'm loading an mvc 3 partial view via JQuery Get. The JQuery UI elements (autocomplete combobox, and button) in the partial are not displaying as J

  • jQuery change text in div using the "data" attribute 2011-04-29

    In jQuery Tabs UI, I'm using this function (thanks to SO'ers) to change the CSS of a div in order to show a particular image according to the data-image attribute of the active tab. Function: var img = $(ui.panel).data("image"); $("#headerwrapper") .

  • Using jquery animate to highlight div on load 2011-06-18

    I have a simple notification system. I want to use jquery to highlight the div onload by changing the background color and go back to normal after 500ms just a flash. Similar to when we answer questions on Stackoverflow. Simple enough to grab attenti

  • jquery hover element swaping elements 2011-06-24

    I am trying to use jquery hover element to swap in and out two elements-- a spanish heading and text with an english heading and text. I want the spanish heading and text to be on the page first, and then have the english heading and text appear (and

  • Using jQuery to Select a DIV that exists only on mouseover 2011-07-02

    I have a couple of div that do not exist until the user places his mouse over some img which causes the div to popup, done via Google Maps API. How can I use jQuery to select this div when it is created (pops up on screen)? Current Code: $(function()

  • jQuery .appendTo(element) not working in all IE versions? 2011-07-21

    I have the following Javascript code that sorts divs on my page: $(function() { var productContainer = $('.productBoxWrapper'); function sortByPriceAsc (a,b){ return Number( jQuery(a).find('.productPriceForSorting').text() - $(b).find('.productPriceF

  • JQuery - use element with DOMNodeInserted 2011-07-25

    For sure this question is very easy, but I just cannot figure this out. I'm using DOMNodeInserted event to detect when a new element is inserted. I don't know how to use the current element, for example to get it's parent id. Now I have the function

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.152 (s). 11 q(s)