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
304 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
Comment Utility
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
Comment Utility
ysfx, does the attr call in question set one attribute with its related value?
0
 
LVL 2

Author Comment

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

Accepted Solution

by:
dnatal earned 0 total points
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
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…

763 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

11 Experts available now in Live!

Get 1:1 Help Now