I am newbie to jQuery.
In netbeans I have jquery-1.7.2.js where all HTML files are present. I am creating JSF 2.0 project.
Below is the code I have
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<h:head>
<title>Welcome to MySite.</title>
</h:head>
<script language="text/javascript" src="#{facesContext.externalContext.requestContextPath}/faces/jquery-1.7.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
alert('I am here...');
$("#table tr:last").after("<tr><td>some</td><td>content</td></tr>");
});
</script>
I believe with this code, whenever document gets loaded, I should have got alert as Hi, I am here...
however I am not getting any alert.
Also, when I see view source & click on jquery-1.7.2.js
, it gets opened.
Any idea why I am not getting alert?
I am following tutorial provided here, still no luck. :(
It seems like a bad location of file, I dont where exactly you placed the jquery file in your web app , but anyway It should be located in folder under the resources folder, So...
Add resources
folder under the WebContent
and inside resources create js
folder
then access the files like this
<h:outputScript name="js/jquery-1.7.2.js" target="head" />