Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-12-2011, 01:33 AM   PM User | #1
BrightNail
Regular Coder

 
Join Date: Jun 2002
Posts: 349
Thanks: 2
Thanked 0 Times in 0 Posts
BrightNail is an unknown quantity at this point
coneNode - how do you make it work for this?

I have the following div elements.

<div id="parentDiv">
<ul id="ulDiv">
<li class="items">
<span class="shade1">
<span class="shade2">
<a class="shade3" href=""></a>
</span>
</span>
</li>
</ul>
</div>

I need to reiterate thru some data and basically append a LI items onto the ulDiv --

So, rather than creating a bunch of elements, I thought to cloneNode 'spotlightentry'
and thru each iteration of data just plug data into the cloned item and then APPEND it to ulDiv.

I am sorta stuck. I have this, but things aren't working out.
(items is the data I am reiterating thru).

var display = $('ulDiv').select('.items').cloneNode(true);
display.select('.items')setStyle({
backgroundImage: "url("' + items.image + '")";
});
display.select('.shade1').innerHTML = items.title;
display.select('.shade2').href = items.link;
display.select('.shade2').update= items.linkname;

$('lulDiv').insert({bottom: display});

I also think I am suppose to remove/delete the initial element i am cloning, but not sure how to do that.

Any advice?
BrightNail is offline   Reply With Quote
Old 02-15-2011, 06:14 PM   PM User | #2
BrightNail
Regular Coder

 
Join Date: Jun 2002
Posts: 349
Thanks: 2
Thanked 0 Times in 0 Posts
BrightNail is an unknown quantity at this point
bump - any thoughts?
BrightNail is offline   Reply With Quote
Old 02-15-2011, 06:29 PM   PM User | #3
venegal
Gütkodierer


 
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
venegal has a spectacular aura aboutvenegal has a spectacular aura about
What framework are you using there? Prototype? I can't really help you with that. If you want, I can move this thread into the frameworks forum for you, though — maybe you'll get more help there.

Anyway, I don't really see any need for that clone business, if all you want to do is append some elements. Also, I don't see you iterating through the items anywhere.
venegal is offline   Reply With Quote
Old 02-15-2011, 06:30 PM   PM User | #4
oVTech
Regular Coder

 
oVTech's Avatar
 
Join Date: Nov 2010
Location: USA
Posts: 296
Thanks: 4
Thanked 54 Times in 52 Posts
oVTech is an unknown quantity at this point
some links might help:
http://stackoverflow.com/questions/9...ascript-jquery

http://stackoverflow.com/questions/1...s-using-jquery

http://stackoverflow.com/questions/2...nts-outer-html

http://api.jquery.com/clone/
__________________




I don't know, I don't care, and it doesn't make any difference!
-Albert Einstein-



oVTech is offline   Reply With Quote
Old 02-15-2011, 06:34 PM   PM User | #5
venegal
Gütkodierer


 
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
venegal has a spectacular aura aboutvenegal has a spectacular aura about
This doesn't look at all like jQuery.
venegal is offline   Reply With Quote
Old 02-15-2011, 06:42 PM   PM User | #6
oVTech
Regular Coder

 
oVTech's Avatar
 
Join Date: Nov 2010
Location: USA
Posts: 296
Thanks: 4
Thanked 54 Times in 52 Posts
oVTech is an unknown quantity at this point
Well, you caught me! I didn't even look at the code. As soon as I saw $(' '), I assumed it was jQuery since most people that post questions here with frameworks are using jquery - at least it seems like it.

OH! And it looks a lot like jquery considering the syntax, the select func and of course that setStyle could be his own function and that he messed up with the cloneNode function and ....etc....
__________________




I don't know, I don't care, and it doesn't make any difference!
-Albert Einstein-




Last edited by oVTech; 02-15-2011 at 06:49 PM..
oVTech is offline   Reply With Quote
Old 02-15-2011, 08:29 PM   PM User | #7
BrightNail
Regular Coder

 
Join Date: Jun 2002
Posts: 349
Thanks: 2
Thanked 0 Times in 0 Posts
BrightNail is an unknown quantity at this point
hey,

Using prototype.

I am using the clone, because I need it to be robust and "professional". I initially did it as just creating the elements and appending them to the div, but it is not "corporate" enough...lol.
BrightNail is offline   Reply With Quote
Old 02-15-2011, 09:13 PM   PM User | #8
venegal
Gütkodierer


 
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
venegal has a spectacular aura aboutvenegal has a spectacular aura about
I see, you aim to be "enterprisey", and cloning stuff without a real need to certainly does the trick. Is that also why you use Prototype instead of jQuery? Well, whatever floats your boat, as long as you get it working. Don't hold your breath for much help with that, though, as we generally aim to simplify, not to convolute.
venegal is offline   Reply With Quote
Old 02-15-2011, 09:26 PM   PM User | #9
BrightNail
Regular Coder

 
Join Date: Jun 2002
Posts: 349
Thanks: 2
Thanked 0 Times in 0 Posts
BrightNail is an unknown quantity at this point
I am confused.

1. We use prototype here at work

2. Creating "new Element" seems to have "more" overhead than the more robust way of cloning a div structure and just slotting in items.

Also, I want to know how to do this because the new Element way is within my knowledge base. I don't know how to make clone work, so then I got to 'wanting' to do it, because to me - seems more enterprising. I don't think that is a bad thing.

please assist :-)
BrightNail is offline   Reply With Quote
Old 02-15-2011, 10:40 PM   PM User | #10
venegal
Gütkodierer


 
Join Date: Apr 2009
Posts: 2,127
Thanks: 1
Thanked 426 Times in 424 Posts
venegal has a spectacular aura aboutvenegal has a spectacular aura about
I thought you meant those quoted "professional" and "corporate" as a joke. Also, "enterprisey" is generally understood as meaning overly complex and convoluted, so that's not a good thing to go for.

So, since you want help — I don't know much about Prototype, but it's enough to make your code completely fall apart, line by line:


Code:
var display = $('ulDiv').select('.items').cloneNode(true);
I don't see this working at all. select() returns an array, which doesn't have a cloneNode method. Let's pretend this somehow works, though, to see what the rest of your code does:

Code:
display.select('.items')setStyle({
Syntax error, you're missing the dot before setStyle.
Also, select still returns an array, which doesn't have a setStyle method.
Also, select searches the descendants of display, but display itself (and not one if its descendants) has class 'items', so it will return an empty array.

Code:
backgroundImage: "url("' + items.image + '")";
});
Syntax error, completely wrong usage of quotes.

Code:
display.select('.shade1').innerHTML = items.title;
display.select('.shade2').href = items.link;
display.select('.shade2').update= items.linkname;
Same thing as above, none of this works, because select returns an array.
Also, shade2 isn't a link but a span, so setting its href property is useless.
Also, shade2 is nested inside shade1, so once you set shade1's innerHTML property, shade2 will be gone anyway and select will return an empty array.

Code:
$('lulDiv').insert({bottom: display});
'lulDiv' is probably just a typo, but still.



So, there you go. Those were more issues than lines of code.


Also, I have no idea what 'spotlightentry' is supposed to be, since it's not in your code. (Generally, cloning like this is ok, btw; it sounded like you were trying to do something else on first read-through, because of that missing piece of information.) And you still haven't shown the actual loop.

All in all I'd say you shouldn't aim to be "professional" or "corporate" or any of those meaningless words, you should just take some time to learn the tools you are working with.


Anyway, I've moved this to the frameworks forum. Maybe someone feels like cleaning up your code there.
venegal is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:02 AM.


Advertisement
Log in to turn off these ads.