This will be helpful to some one who is looking for a similar kind of scenario. What I explain here is simple piece of code, but to achieve that in my application as per my need I struggled to find the appropriate one.
My design is static but I am framing this one dynamically in my application, and also here I am showing one section whereas in my application there are multiple sections where I can have duplicate records. When I am removing data I need to make one section inactive and need to removethe entire div in one section.
This is a continuation for my code snippet here. This is the actual problem I have in my application. For a basic one check my code here,
This is how my design and entire code looks, please find the attached code for further reference,
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="favandprev.aspx.cs" Inherits="AP.ROW.UI.favandprev" %>
-
- <!DOCTYPE html>
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <link href="css/literal.css" rel="stylesheet" />
- <script src="scripts/jquery-2.2.0.js"></script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div id="no-list">
- No Data
- </div>
- <div id="literal-list" class="literal-offer">
- <table style="height: 20px">
- <tbody>
- <tr>
- <td style="vertical-align: middle">
- <h3>Favorite List</h3>
- </td>
- </tr>
- </tbody>
- </table>
- <div class="literal-offer-product">
- <div class="image-wrap">
- <img class="checkout-offer-img" src="/Images/jerry.png" />
- </div>
- <div class="literal-offer-info">
- <strong>I am Jerry</strong><br />
- <br />
- <a id="removeLiteral0" class="favorite active" onclick="javascript:return removeMe(this,'Y');">Favorite</a>
- </div>
- </div>
- <div class="clear"></div>
- <div class="literal-offer-product">
- <div class="image-wrap">
- <img class="checkout-offer-img" src="/Images/superman.jpg" />
- </div>
- <div class="literal-offer-info">
- <strong>I am Super Man</strong><br />
- <br />
- <a id="removeLiteral1" class="favorite active" onclick="javascript:return removeMe(this,'Y');">Favorite</a>
- </div>
- </div>
- <div class="clear"></div>
- <div class="literal-offer-product">
- <div class="image-wrap">
- <img class="literal-offer-img" src="/Images/skate.png" />
-
- </div>
- <div class="literal-offer-info">
- <strong>Skate Board</strong><br />
- <br />
- <a id="removeLiteral2" class="favorite active" onclick="javascript:return removeMe(this,'Y');">Favorite</a>
- </div>
- </div>
- <div class="clear"></div>
- <div class="literal-offer-product">
- <div class="image-wrap">
- <img class="literal-offer-img" src="/Images/bsnl.jpg" />
-
- </div>
- <div class="literal-offer-info">
- <strong>BSNL</strong><br />
- <br />
- <a id="removeLiteral3" class="favorite active" onclick="javascript:return removeMe(this,'Y');">Favorite</a>
- </div>
- </div>
- <div class="clear"></div>
- <div class="literal-offer-product">
- <div class="image-wrap">
- <img class="literal-offer-img" src="/Images/pendrive.jpg" />
-
- </div>
- <div class="literal-offer-info">
- <strong>Pen Drive</strong><br />
- <br />
- <a id="removeLiteral4" class="favorite active" onclick="javascript:return removeMe(this,'Y');">Favorite</a>
- </div>
- </div>
- </div>
-
- <div id="previously-viewed" class="literal-offer">
- <table style="height: 20px">
- <tbody>
- <tr>
- <td style="vertical-align: middle">
- <h3>Previously Viewed</h3>
- </td>
- </tr>
- </tbody>
- </table>
- <div class="literal-offer-product">
- <div class="image-wrap">
- <img class="checkout-offer-img" src="/Images/jerry.png" />
- </div>
- <div class="literal-offer-info">
- <strong>I am Jerry</strong><br />
- <br />
- <a id="removeLiteral0" class="favorite active" onclick="javascript:return removeMe(this,'N');">Favorite</a>
- </div>
- </div>
- <div class="clear"></div>
- <div class="literal-offer-product">
- <div class="image-wrap">
- <img class="checkout-offer-img" src="/Images/superman.jpg" />
- </div>
- <div class="literal-offer-info">
- <strong>I am Super Man</strong>
- <br />
- <a id="removeLiteral1" class="favorite active" onclick="javascript:return removeMe(this,'N');">Favorite</a>
- </div>
- </div>
- <div class="clear"></div>
- <div class="literal-offer-product">
- <div class="image-wrap">
- <img class="literal-offer-img" src="/Images/skate.png" />
- </div>
- <div class="literal-offer-info">
- <strong>Skate Board</strong><br>
- <br />
- <a id="removeLiteral2" class="favorite active" onclick="javascript:return removeMe(this,'N');">Favorite</a>
- </div>
- </div>
- <div class="clear"></div>
- <div class="literal-offer-product">
- <div class="image-wrap">
- <img class="literal-offer-img" src="/Images/bsnl.jpg" />
- <a id="lnkQuickView" class="quick-view btn quick-hide" data-target="#quickviewmodal" data-toggle="modal" href="/Order/QuickViewPopUp.aspx?R=2586JS75&src=QuickView-Checkout-PreviouslyViewed">Quick View</a>
- </div>
- <div class="literal-offer-info">
- <strong>BSNL</strong><br>
- <br />
- <a id="removeLiteral3" class="favorite active" onclick="javascript:return removeMe(this,'N');">Favorite</a>
- </div>
- </div>
- <div class="clear"></div>
- <div class="literal-offer-product">
- <div class="image-wrap">
- <img class="literal-offer-img" src="/Images/adobe.jpg" />
- </div>
- <div class="literal-offer-info">
- <strong>Adobe</strong>
- <br />
- <a id="removeLiteral5" class="favorite active" onclick="javascript:return removeMe(this,'N');">Favorite</a>
- </div>
- </div>
- <div class="clear"></div>
- <div class="literal-offer-product">
- <div class="image-wrap">
- <img class="literal-offer-img" src="/Images/pendrive.jpg" />
-
- </div>
- <div class="literal-offer-info">
- <strong>Pen Drive</strong><br />
- <br />
- <a id="removeLiteral4" class="favorite active" onclick="javascript:return removeMe(this,'N');">Favorite</a>
- </div>
- </div>
- </div>
- <br />
- </form>
- <script type="text/javascript">
- $("#no-list").hide();
- function removeMe(controlID, isRemove) {
- var item = $('#literal-list').find('.literal-offer-product').find('.literal-offer-info').find("a[id='" + controlID.id + "']");
- var prev = $('#previously-viewed').find('.literal-offer-product').find('.literal-offer-info').find("a[id='" + controlID.id + "']");
- var isExists = $('#literal-list').find('.literal-offer-product').find('.literal-offer-info').find("a[id='" + controlID.id + "']").length;
- var favCount = $('#literal-list').find('.literal-offer-product').length;
- var removeDiv = controlID.id;
- if (isRemove == "Y") {
- item.parent().parent().remove();
- prev.removeClass("favorite active");
- prev.addClass("favorite");
- }
- else {
- if (isExists) {
- item.parent().parent().remove();
- $('#' + controlID.id).removeClass("favorite active");
- $('#' + controlID.id).addClass("favorite");
- }
- else {
- if (favCount < 5) {
- if ($('#' + controlID.id).hasClass('favorite')) {
- $('#' + controlID.id).removeClass("favorite");
- $('#' + controlID.id).addClass("favorite active");
- }
- var v = $('#literal-list').html();
- $('#literal-list').html(v + controlID.parentNode.parentNode.outerHTML);
- }
- else
- {
- if ($('#' + controlID.id).hasClass('favorite active')) {
- $('#' + controlID.id).removeClass("favorite active");
- $('#' + controlID.id).addClass("favorite");
- }
- else
- {
- $('#' + controlID.id).removeClass("favorite");
- $('#' + controlID.id).addClass("favorite active");
- }
- }
- }
- }
-
- if ($('#literal-list').find('.literal-offer-product').length == 0) {
- $('#literal-list').hide();
- $("#no-list").show();
- }
- else {
- $('#literal-list').show();
- $("#no-list").hide();
- }
- }
- </script>
- </body>
- </html>