Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

switching table attributes with JS

Posted on 2006-03-27
2
Medium Priority
?
201 Views
Last Modified: 2011-09-20
Hi there,

I'm trying to do a merge of the following two scripts:


#1:
------------------------------------------------------
<body onload="classChange();">
<script type="text/javascript">
<!--
function classChange() {
      for (i=0;i<document.getElementsByTagName("p").length; i++) {
            if (document.getElementsByTagName("p").item(i).className == "main"){
                  document.getElementsByTagName("p").item(i).style.color = "red";
            }
      }
}
//-->
</script>


#2:
------------------------------------------------------
function changeSize(px){
   var table = document.getElementById("tableMain2");
   table.setAttribute("width",px);
}


The issue is that I need to change the hard coded width of a table that only has class="main" attributed to it.  Unfortunately, I cannot change the HTML code.

Thanks!

0
Comment
Question by:seamusseamus
2 Comments
 
LVL 49

Accepted Solution

by:
Roonaan earned 2000 total points
ID: 16307611
You can use:

function tableMainChange() {
for(i = 0; i < document.getElementsByTagName("table").length;i++)
          if (document.getElementsByTagName("table").item(i).className == "main"){
               document.getElementsByTagName("table").item(i).setAttribute("width", "100px");
          }
}
}

-r-
0
 

Author Comment

by:seamusseamus
ID: 16509104
sorry for the delay in accepting this answer... worked like a charm!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…
Suggested Courses

580 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