score:1
Accepted answer
This is how you can use variable in jquery script "@variable name"
@{
var items = Utils.GetImages("background", 3);
var backgroundUrl = items.FirstOrDefault();
}
<script type="text/javascript">
$(document).ready(function () {
$('body').css({
'background-image': 'url(' + "@backgroundUrl.ToString()" + ')',
'background-position': '50% 0%', 'background-attachment': 'fixed'
});
});
</script>
Related Query
- Jquery dynamic background image url does not work
- Jquery Draggable does not work for dynamic content
- jQuery dynamic adding columns to a table does not work
- on click does not work after inserting dynamic HTML with jquery
- jquery unbind and off does not work on image
- My JQuery image slideshow does not seem to work
- jquery form plugin in wordpress to upload an image file does not work as expected
- jQuery change background image url to uploaded image
- Why does jQuery on('load', function(){}); not fire if the the image loads before the load is bound? IE and Localhost
- CSS text over image hover does not work
- making jquery object from variable does not fully work
- Why does jQuery work on one page and not another?
- keyup does not work at dynamic added field
- Jquery attr method does not work on 'onMouseEnter'
- jquery ui slider scrollbar does not work when div is display none
- JQuery Datetime picker plugin does not work with AngularJS in ng-view
- jQuery Selector escaping colon ":" works in IE but does not work elsewhere
- jQuery the execution of my function in while does not work
- jquery fading span does not contain the image if size changes dynamically
- JQuery REST call does not work
- Migrating js file from prototype to jQuery does not work
- New to Jquery - it does not load or work at all on any browsers
- Jquery slider does not work on iPad works fine on browser
- Jquery Ajax Promise does not work
- Jquery Ajax Promise does not work
- Menu element does not work after using jquery replace with
- Jquery click eventObject does not work in Firefox
- Why jquery "change" event does not work in my example?
- AJAX request using jQuery does not work
- jQuery why this does not work $(":input").change(function(){});
- Add class jQuery does not work
- jQuery slider and background image works in Firefox but not Chrome
- jQuery Cached Selector does not work correctly
- Jquery validation does not work
- Change background image of an iframe body with Jquery if certain URL
- jQuery custom UL type dropdown: blur() does not work on iOS
- Jquery Scroll function does not work here
- jQuery Color Animation - does not fade back to background color
- jQuery click does not work in pop-up
- jquery autocomplete does not work for some reason
- jQuery slider does not work
- Jquery .html does not work
- Using simplemodal (modal) -- Does not work right in IE -- modal displays but background elements are clickable; works in firefox, though
- jQuery die() does not work
- jQuery $.ajax does not work
- Why html() function in JQuery does not work in IE
- JQuery FadeIn - Fade in the background image div but not the contents div?
- Jquery callback script executes but does not work
- creating jquery plugin - does not work when used on the same element twice
- JQuery - IE 6,7 Opacity does not work
More Query from same tag
- C# Lazy loading & Ajax
- click event does not work on the text which is created by javascript
- Slide toggle in list items, but should not toggle when click on the child item
- upgrading greybox with fancybox not working
- How to create a box which appears upon clicking menu item?
- Selective mouseenter/mousedown in jQuery
- Special character check with jquery
- easypaginate error, it doesn´t work
- does .submit ajax call need to be wrapped in $(function () {})
- If Statement Using JavaScript and PHP
- What is the most popular javascript framework in combination with jquery?
- DataTables: Initialize two DataTables on same page in a separate way
- code works in js fiddle but not in dreamweaver or on server
- How to change color of filtered information when it is in search mode (Datatables)
- Bootstrap navbar with content above does not stick
- Rails: jquery autocomplete in a search form
- Redirect a page at specific instant
- AJAX call: Invalid web service call, missing value for parameter
- Combining Rails and jQuery, CSS?
- jQuery can't affect "outside" divs
- angular JS and ng-keydown on non input field?
- adding click to google maps api v3
- Create side menu in bootstrap?
- onHover font colour not changing
- how to identify the position of the error tag
- jQuery $.get returns white error page when handling errors
- How to prevent modal popup asp.net
- Applying a jQuery event to multiple classes on a page
- jQuery JSON SyntaxError: JSON.parse only on FIREFOX
- get img path on clisk with jquery