Solved

What does element.attr('foo', 'bar') do? and what does element.attr('foo', 'bar').toggle(functiona, functionb) do?

Posted on 2008-06-18
4
311 Views
Last Modified: 2008-06-26
What does element.attr('foo', 'bar') do? and what does element.attr('foo', 'bar').toggle(functiona, functionb) do?

What I'm really trying to do is modify the attached code snippet so that, in the case that an object has no child objects, the "Subcategory" link does not appear.

taxDiv.each(function(index,element) {
		id = $(element).attr('id');
		t = id.split('-',2);
		itemCode = t[1];
		ele = $('<a><b>Subcategories&raquo;</b></a>').attr('id', 'more-'+itemCode).toggle(RRDB.sic.getChildren,RRDB.sic.removeChildren)
		$(element).append(ele);
	});

Open in new window

0
Comment
Question by:dnatal
  • 3
4 Comments
 
LVL 6

Expert Comment

by:ysfx
ID: 21815134
The attribute is all the extra values contained within the element tag. For example <a href="link.html" id="link1" class="myClass">Click Here</a>, href, id, and class are attributes of the anchor (i.e. a) tag.

You are probably looking for something like innerHTML:
http://developer.mozilla.org/en/docs/DOM:element.innerHTML
0
 
LVL 2

Author Comment

by:dnatal
ID: 21815197
ysfx, does the attr call in question set one attribute with its related value?
0
 
LVL 2

Author Comment

by:dnatal
ID: 21815332
I think I figured out what I need to do, but thanks.
0
 
LVL 2

Accepted Solution

by:
dnatal earned 0 total points
ID: 21815363
attr('foo', 'bar') sets one attribute with its related value.
toggle(functiona, functionb) assigns those functions to the object to be called on event.

The updated code is attached, although it's not 100% yet.
taxDiv.each(function(index,element) {
		id = $(element).attr('id');
		t = id.split('-',2);
		itemCode = t[1];
		thisID = 'more-'+itemCode;
		thisBaseCode  = thisID.substr(thisID.indexOf('-')+1);
		ele = $('<a><b>Subcategories&raquo;</b></a>').attr('id', 'more-'+itemCode).toggle(RRDB.sic.getChildren,RRDB.sic.removeChildren)
		if(RRDB.sic.hasChildren(thisBaseCode)){
			$(element).append(ele);
		}

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how can i get the string decoded ? 2 28
Not allowed to load local recource. 4 35
Add shadow behind div 5 25
asp Google Map 2 32
This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question