Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I am starting an angular js application and I ran into a snag. I have a html page that has a few divs with icons in them, on mouse over, I want the background to change color. This is working fine using jquerys $(document).ready(function(){ approach

THis page changes content based on an id in the url (e.g. page/apps/1 - 1 for appid) However, the jquery for setting the background colors using onmouse over events is only called when the page is loaded the first time. If I click a link to update a new application, the jquery does not take effect even though the method is definitely called If i navigate directly in the browser to the page in question, the jquery works as expected, its only when I click links on my page to load up pages without doing a browser refresh that the jquery does not work

Any help on this is greatly appreciated

Code is as follows Page which is loaded

    <div class="row" style="border:0px solid red;">
    <div class="col-md-1 createSection-spacer-left-width"></div>
    <div class="col-md-11">
        <ul class="nav nav-boxed nav-justified nav-box-text createSection-content-width">
            <li><a href="javascript:;" id="rssAndUrlsLi"><i id="rssAndUrls" class="genericNavBox rssAndUrls"></i> Rss & Urls</a></li>
            <li><a href="javascript:;" id="articleURLLi"><i id="articleURL" class="genericNavBox articleURL"></i> Article URL</a></li>
            <li><a href="javascript:;" id="googleAlertsLi"><i id="googleAlerts" class="genericNavBox googleAlerts"></i> Google Alert</a></li>
            <li><a href="javascript:;" id="writeLi"><i id="write" class="genericNavBox write"></i> Write </a></li>
            <li><a href="javascript:;" id="twitterLi"><i id="twitter" class="genericNavBox twitter"></i> Twitter</a></li>
            <li><a href="javascript:;" id="facebookLi"><i id="facebook" class="genericNavBox facebook"></i> Facebook</a></li>
            <li><a href="javascript:;" id="googlePlusLi"><i id="googlePlus" class="genericNavBox googlePlus"></i> Google +</a></li>
            <li><a href="javascript:;" id="youtubeLi"><i id="youtube" class="genericNavBox youtube"></i> YouTube</a></li>
        </ul>

    </div>

</div>

Javascript file is then loaded at the bottom of this page

<script src="scripts/customMobileAppScripts/createSection.js"></script>

Portion of Code in requested Javascript file

          $(document).ready(function() {
        return setSourceBoxValues();
      });

function setSourceBoxValues() {
$("#rssAndUrlsLi").mouseover((function() {
      return $("#rssAndUrls").addClass("rssAndUrlsActive");
    }));
    $("#rssAndUrlsLi").mouseover((function() {
      return $("#rssAndUrlsLi").css("background-color", "red");
    }));
}

Cheers Damien

share|improve this question
2  
angular recommends not access jquery directly. or accessing jquery via an angular directive. my guess is it's 1. a timing issue and 2. mixing technologies. it will also help if you post the code. – Jason Meckley Nov 6 '14 at 16:07
2  
Post your code. $(document).ready is triggered only when the original DOM tree is built. Subsequent DOM manipulations (including changing views) do not have the same effect. – PM 77-1 Nov 6 '14 at 16:09
    
Code is now posted guys – Damien Gallagher Nov 6 '14 at 16:23
    
Why not doing it with plain css and :hover selector ? – MiTa Nov 6 '14 at 16:24
    
@MiTa I looked at this but I will also be adding click events. i started with the background colors for now but there will be more logic added here. I want to keep it all together – Damien Gallagher Nov 6 '14 at 16:31

Thanks for the help guys

I was able to solve this issue by moving my javascript logic call into my angularjs controller instead of using jquery on page load

Cheers Damien

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.