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
307 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now