tags:

views:

169

answers:

2

Hi,

i am having a Div like

 <div class="float_left" id="fb_contentarea_col2_dropingarea">

  <div data-attr="text" id="div1" class="field_div_style1 rounded_edges1">     </div>
  <div data-attr="text" id="div2" class="field_div_style1 rounded_edges1">     </div>
  <div data-attr="text" id="div3" class="field_div_style1 rounded_edges1 field_div_style">     
 </div>
 </div>

i am trying to find the DIVs id which is having the Class that contains the class field_div_style using JQuery. i have tried it with

alert($("#fb_contentarea_col2_dropingarea div").find("class","field_div_style")); -- alerts object

alert($("#fb_contentarea_col2_dropingarea div").find("class","field_div_style").attr("id")); -- alerts undefined

how to do so??

+3  A: 

You need:

<script type="text/javascript">
$(function() {
    alert($('#fb_contentarea_col2_dropingarea .field_div_style').attr('id'));
});
</script>

Make sure you wrap the code in a ready event or else it won't work as the DOM isn't entirely loaded.

Sbm007
+1  A: 

A couple of things:

$(#fb_contentarea_col2_dropingarea .field_div_style");

is a simple css-style selector to get all elements inside #fb_contentarea_col2_dropingarea that have class field_div_style

No need to use .find() here.

If there is more than one, this will return a collection of elements that you'll have to loop or work with in some way, so alerting will return as in your example. I recommend you use firefox and download firebug, so you can use console.log() instead to get more detail.

ScottE
You can also simply use the `.toSource()` JavaScript method to see inside the Object: https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Object/toSource
deizel