Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
Medium Priority
?
324 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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…

604 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