473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Editing DIVs with classname JQuery

258 100+
Hi everyone
I'm using JQuery to add an onClick event to all DIV tags on my HTML page

Here's the code:
Expand|Select|Wrap|Line Numbers
  1. $(document).ready(function(){
  2.    var js = "alert(this.className); return false;";
  3.    var newclick = new Function(js);
  4.    $("div").attr('onclick', '').click(newclick);
  5. });
  6.  
This code works fine but the problem is that I only need DIV tags which have a class attribute.

for Example :

Expand|Select|Wrap|Line Numbers
  1. <div class='test1'></div>
  2. <div></div>
  3. <div class='test2'></div>
  4.  
In the above code only first and third DIVs should be selected

Thanks / Behzad
Sep 5 '11 #1

✓ answered by Dormilich

since jQuery uses CSS selectors you should be able to use $("div[class]") (or something like that, you would have to look up the correct syntax, if that fails)

2 1692
Dormilich
8,658 Expert Mod 8TB
since jQuery uses CSS selectors you should be able to use $("div[class]") (or something like that, you would have to look up the correct syntax, if that fails)
Sep 6 '11 #2
bnashenas1984
258 100+
Thank you Dormilich
Your code did the magic :)
Sep 6 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: tabert | last post by:
I want to use JavaScript when a button is clicked to show and hide a SPAN or DIV. This works in both IE and Netscape, but what I'd like to happen is for there to be no white space where the hidden...
4
by: bridgemanusa | last post by:
Hi All: I have a very long page of html that I want to take portions and hide them in divs, then show when a link is clicked. I have the hide show part working when the link is clicked, however...
2
by: samuelberthelot | last post by:
Hi, I have a number of divs on my page, which are generated dynamically from records in a database. Each div is collapsible (display:none or display:block) when clicking on the header (a...
8
by: tbobker | last post by:
Because of the nature of what im trying to do, the ids of the divs im creating are all from a foreach loop array but the div is classed so when i click an onsubmit i need to find all the IDs for a...
2
by: insanity | last post by:
Can anyone help me with a problem that I have with apparently unrelated text disappearing in IE7 when I set a className. This does not happen in Firefox. I am trying to create an Ajax driven...
12
by: daniel2335 | last post by:
This problem is everywhere! I have read all forums available, spent about 40+ hours on it and lost a bit of hair. I was going to explain what its ment to look like but I just realised removing the...
4
by: Steffan A. Cline | last post by:
I have a situation where I am making a calendaring solution and need to have 5 scrollable divs side by side in a week view but the week div needs to scroll left and right. As it sits now, unless...
53
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
3
by: mberkom | last post by:
I've got a jquery selector I'm trying to get done and since I'm somewhat new to jquery I'm stumped. Essentially. I'm trying to get a div within divs with the class "card" that do not have the class...
6
by: aaronkmar | last post by:
Trying to get a loading image to spin while the query is loading. I can get the data div to fade in, but I can't seem to figure out how to get the gif while the query is loading. I'm using two...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.