0

How to keep click event(colour change event) if URL has changed after click.

this script below that for click a tag, the URL will changing it.

<script type="text/javascript">
function sigun(sigun) {
    location.href = '/openSec.do?sigun=' + sigun + '&categoryCode1=select1' + '&categoryCode2=mon' + '&categoryCode3=00';
}

this JSP code is sample code. if section1 cliked, the URL will chaned /openSec.do?sigun=' + section1 ..... like that. I think this mean the page refresh it.

<div class="gnmap_txt_area">
    <div class="cw map_box">
        <div class="map_txt01">
            <a href="javascript:sigun('section1');">
                <c:forEach var="eventCnt" items="${eventCnt}">
                    <c:if test="${eventCnt.signgu == 'section1' && fn:length(eventCnt.signgu) > 0}"> 
                    <div class="jb-title"><img src="/images/ico_map_event.png" alt="eventit"> </div></c:if>
                    <div class="jb-text">
                        <c:forEach var="eventMain" items="${eventMain}">
                            <c:if test="${eventMain.signgu == 'section1'}">
                                <span style="font-size: 5px">* ${eventMain.evenNm} <br /></span>
                            </c:if>
                        </c:forEach>
                    </div>
                </c:forEach>
                <p>section1</p>
            </a>
        </div>
    </div>
</div>

And JS blew is click event code.

    $('.map_box').click(function () {
    $('.map_box').removeClass('on');
    $(this).addClass('on');
});

if clicked select1, the div (class="cw map_box") will change (class="cw map_box on")..

it works well but the problem is when i clicked select1 the page refresh it then click event also disappear.. is there anay way to keep click event? it just color change event

thank you

hayley
  • 45
  • 5
  • The question is unclear. Do you want to prevent navigating away from the current page? See this related [question](https://stackoverflow.com/questions/5963669/whats-the-difference-between-event-stoppropagation-and-event-preventdefault) – Yogi Dec 14 '22 at 08:35

0 Answers0