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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Slush on text 2 25
How does this modal gets closed? 6 41
Check for Numeric Phone Field 14 45
Leaflet map example works but I want to make a change to it 5 25
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

732 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