Karthik Bammidi
Karthik Bammidi

Reputation: 1851

How could i apply separate styles for odd and even div tags

I am working on asp.net mvc 4 with razor view. I am trying to display the odd div tags with style float:left and even div tags with style float:right. Here my div tags are like,

    <div id="content" style="padding-top:80px;">
    @foreach (var item in (List<System.Data.DataRow>)ViewBag.List)
    {
        <a href="@string.Format("Products?id={0}",item[0])">
        <div class="img">

            <table align="center" cellspacing="12">
                <tr>
                    <td style="text-align: center;">
                        <b>@item[1]</b>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: center; color: DodgerBlue; font-size: xx-large; border-top: 1px solid Gray;
                        border-bottom: 1px solid gray; font-weight: bolder;">
                        $@item[2]
                    </td>
                </tr>
                <tr>
                    <td style="text-align: center">
                        @item[3]
                    </td>
                </tr>
                <tr>
                    <td style="text-align: center">
                        No Trail period
                    </td>
                </tr>
                <tr>
                <td>
                <div class="divOuter" style="float:left;margin:4px;width:100%;height:40px;text-align:left">
                 @foreach (var i in ProductOption.ProductOptions(Convert.ToInt32(item[0])))
                 {
                     <div class="divInner" style="display:inline;width:50%;"><input type="checkbox" value="@i[0]" checked="checked" /><span style="line-height:20px;font-weight:bold;">@i[0]</span></div>
                 }
                 </div>
                </td>
                </tr>
            </table>
        </div></a>
    }
</div>

I have uses jquery like,

 $(document).ready(function () {
           $("div.divOuter div.divInner:odd").css("float","left");
           $("div.divOuter div.divInner:even").css("float", "right");
       });

How could i apply float:left for odd div tags and float:right for even div tags. please guide me.

Upvotes: 0

Views: 612

Answers (2)

user1269989
user1269989

Reputation: 117

You are missing a big part - there cannot be multiple ids with the same name. You can use a class and then use a selector and it will work.

See here: http://jsfiddle.net/FMp35/3/

Upvotes: 0

Jacob
Jacob

Reputation: 78848

Instead of setting the id of the inner divs, set their class to divInner. Then change your selectors to look like this:

 $(document).ready(function () {
       $("div.divOuter .divInner:odd").css("float","left");
       $("div.divOuter .divInner:even").css("float", "right");
   });

IDs are supposed to be unique within in an HTML document.

Upvotes: 2

Related Questions