1. How to check an element is visible or not using jQuery
Answer: Use Jquery : visible selector
if($("p").is(":hidden")){}
if($("div").is(":hidden")){}
2. How to select an element by name with jQuery?
Answer: This can be acheived by two ways.
WAY 1: by using jquery selector.
Example1: with id
$("#foo") Selects all elements with the id="foo".
Example2: SELECTS ALL ELEMENTS
$("*") Selects all elements
Example3: SELECTS ALL ELEMENTS WITH CLASS=BAR
$(".bar") Selects all elements with class=bar.
Example4: SELECT ALL P ELEMENTS
$("p") Selects all P elements
Example5: SELECT P ELEMENTS WITH BAR CLASS
$("p.bar") Selects all elements with the id="foo".
WAY 2: GET ELEMENT BY NAME USING JAVASCRIPT AND PASS IT TO JQUERY
selector = document.getElementsByName('nameOfElement');
element = $(selector);
eg:- If you want to show or hide an element , then simply do like this
element.hide() or element.show()
3. How to add text to an existing div with jquery
Answer: var a = "Hello USMTECHWORLD"; $('#dvscore').before(a);
4. How to add jquery file in View of ASP.Net MVC
Answer:
<script src="~/Scripts/jquery-1.10.2.js">
Inside the somesamples.js file, you can write all the jquery scripts related to your ASP.NET MVC view.
@Scripts.Render("~/Scripts/somesamples.js")
5. What is the use of NoConflict method in jQuery
Answer:
Jquery used $ sign for performing jquery actions.There are other frameworks which uses the same $ sign, for eg:- angular,knockout etc.
so if 2 different frameworks uses same $ symbol, then one of them might stop working.In order to prevent this jquery introduces a function
called noConflict().You can use your own custom variable to perform jquery action like the below example.
var j = $.noConflict();
j(document).ready(function(){
j("button").click(function(){
j("p").text("jQuery Rocks!");
});
});
<p>This is a paragraph.<p>
<button>Click jQuery<button>
6.What is the most used selector in jQuery?
Answer:
The selectors in jquery start with dollar sign and parenthesis$().
The most used selectors in jquery are ID and element.
Always use '#' character to select elements by ID. (Eg:- <div>$('#dvscore') <div>)
7.How will you check, which version of jQuery you are using in a website?
Answer:
The command used to check version of jquery that you are using in your website is "$.fn.jquery".This command can be
run on the console window of any browser.
8.What is event.preventDefault()?
Answer:
It stops the default action of an element from happening.For eg:-it prevents the submit button from submitting a form,prevents link being clicked.
The above click event prevents the click event being performed.
document.getElementById("Save").addEventListener("click", function(event){
event.preventDefault()
});
9.What is the difference between response and response.d?
Answer:
The response will return as object and also as string, whereas with response.d we can get the data.
for eg:-if your ajax call to webmethod returns "True" or "False".so your response will be displayed as "Object" or [Object][object]
so inorder to fetch actual data, you can write as response.d, it will fetch "True" or "False"